From ef12b8d77e51d413d0fe3cd03d4eec7cab13b5eb Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Fri, 30 Jan 2015 17:20:06 +0900 Subject: [PATCH] [#143] intercepting for log4j, logback library --- ....java => LoggingEventOfLog4jModifier.java} | 28 ++++---- .../log/log4j/aspect/LoggingEventAspect.java | 65 ------------------- ...va => LoggingEventOfLog4jInterceptor.java} | 4 +- 3 files changed, 13 insertions(+), 84 deletions(-) rename profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/{LoggingEventModifier.java => LoggingEventOfLog4jModifier.java} (63%) delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/aspect/LoggingEventAspect.java rename profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/interceptor/{LoggingEventInterceptor.java => LoggingEventOfLog4jInterceptor.java} (89%) diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/LoggingEventModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/LoggingEventOfLog4jModifier.java similarity index 63% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/LoggingEventModifier.java rename to profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/LoggingEventOfLog4jModifier.java index 44f26ccf0..05e746310 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/LoggingEventModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/LoggingEventOfLog4jModifier.java @@ -26,16 +26,15 @@ import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass; import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException; import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor; import com.navercorp.pinpoint.profiler.modifier.AbstractModifier; -import com.navercorp.pinpoint.profiler.modifier.log.log4j.interceptor.LoggingEventInterceptor; /** * @author minwoo.jung */ -public class LoggingEventModifier extends AbstractModifier { +public class LoggingEventOfLog4jModifier extends AbstractModifier { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public LoggingEventModifier(ByteCodeInstrumentor byteCodeInstrumentor,Agent agent) { + public LoggingEventOfLog4jModifier(ByteCodeInstrumentor byteCodeInstrumentor,Agent agent) { super(byteCodeInstrumentor, agent); } @@ -48,21 +47,16 @@ public class LoggingEventModifier extends AbstractModifier { try { - //method weaving -// InstrumentClass loggingEvent = byteCodeInstrumentor.getClass(classLoader, javassistClassName, classFileBuffer); -// loggingEvent.weaving("com.navercorp.pinpoint.profiler.modifier.log.log4j.aspect.LoggingEventAspect"); - - - //add interceptor for constructor -// Interceptor interceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.log.log4j.interceptor.LoggingEventInterceptor"); -// -// InstrumentClass loggingEvent = byteCodeInstrumentor.getClass(classLoader, javassistClassName, classFileBuffer); -// loggingEvent.addInterceptor("getMDCCopy", new String[]{}, interceptor); -// return loggingEvent.toBytecode(); - InstrumentClass loggingEvent = byteCodeInstrumentor.getClass(classLoader, javassistClassName, classFileBuffer); - Interceptor interceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.log.log4j.interceptor.LoggingEventInterceptor"); - loggingEvent.addConstructorInterceptor(new String[]{"java.lang.String", "org.apache.log4j.Category", "org.apache.log4j.Priority", "java.lang.Object", "java.lang.Throwable"}, interceptor); + + Interceptor interceptor1 = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.log.log4j.interceptor.LoggingEventInterceptor"); + loggingEvent.addConstructorInterceptor(new String[]{"java.lang.String", "org.apache.log4j.Category", "org.apache.log4j.Priority", "java.lang.Object", "java.lang.Throwable"}, interceptor1); + + Interceptor interceptor2 = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.log.log4j.interceptor.LoggingEventInterceptor"); + loggingEvent.addConstructorInterceptor(new String[]{"java.lang.String", "org.apache.log4j.Category", "long", "org.apache.log4j.Priority", "java.lang.Object", "java.lang.Throwable"}, interceptor2); + + Interceptor interceptor3 = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.log.log4j.interceptor.LoggingEventInterceptor"); + loggingEvent.addConstructorInterceptor(new String[]{"java.lang.String", "org.apache.log4j.Category", "long", "org.apache.log4j.Level", "java.lang.Object", "java.lang.String", "org.apache.log4j.spi.ThrowableInformation", "java.lang.String", "org.apache.log4j.spi.LocationInfo", "java.util.Map"}, interceptor3); return loggingEvent.toBytecode(); } catch (InstrumentException e) { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/aspect/LoggingEventAspect.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/aspect/LoggingEventAspect.java deleted file mode 100644 index c42de4e2e..000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/aspect/LoggingEventAspect.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.profiler.modifier.log.log4j.aspect; - -import com.navercorp.pinpoint.profiler.interceptor.aspect.Aspect; -import com.navercorp.pinpoint.profiler.interceptor.aspect.JointPoint; -import com.navercorp.pinpoint.profiler.interceptor.aspect.PointCut; - -/** - * add transaction id - * @author minwoo.jung - */ -@Aspect -public abstract class LoggingEventAspect { - - //!!!!!!threadLocal 객체로 구현해야할듯 - protected String __transactionId = "[[transactionId==123123123]]"; - - private String get__transactionId() { - return __transactionId; - } - - private void set__transactionId(String __transactionId) { - this.__transactionId = __transactionId; - } - - @PointCut - public Object getMessage() { - Object message = __getMessage(); - - if (message instanceof String) { -// message = this.transactionId + (String)message; - message = __transactionId + (String)message; - } - - return message; - } - - @JointPoint - abstract Object __getMessage(); - - - @PointCut - public String getRenderedMessage() { -// return this.transactionId + __getRenderedMessage(); - return __transactionId + __getRenderedMessage(); - } - - @JointPoint - abstract String __getRenderedMessage(); -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/interceptor/LoggingEventInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/interceptor/LoggingEventOfLog4jInterceptor.java similarity index 89% rename from profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/interceptor/LoggingEventInterceptor.java rename to profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/interceptor/LoggingEventOfLog4jInterceptor.java index e38e28a48..414960006 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/interceptor/LoggingEventInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/log/log4j/interceptor/LoggingEventOfLog4jInterceptor.java @@ -1,7 +1,7 @@ package com.navercorp.pinpoint.profiler.modifier.log.log4j.interceptor; -import org.slf4j.MDC; +import org.apache.log4j.MDC; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; @@ -11,7 +11,7 @@ import com.navercorp.pinpoint.bootstrap.interceptor.TraceContextSupport; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; -public class LoggingEventInterceptor implements SimpleAroundInterceptor, TraceContextSupport, TargetClassLoader { +public class LoggingEventOfLog4jInterceptor implements SimpleAroundInterceptor, TraceContextSupport, TargetClassLoader { private final PLogger logger = PLoggerFactory.getLogger(this.getClass()); private final boolean isDebug = logger.isDebugEnabled();