mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 00:36:02 +10:00
[#143] intercepting for log4j, logback library
This commit is contained in:
+11
-17
@@ -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) {
|
||||
-65
@@ -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();
|
||||
}
|
||||
+2
-2
@@ -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();
|
||||
Reference in New Issue
Block a user