set a new interceptor point for log4j2 to output traceid.
This commit is contained in:
parent
7545ebcc77
commit
7553dff4df
|
|
@ -0,0 +1,10 @@
|
|||
package com.a.eye.skywalking.toolkit.log4j.v2.x;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/12/11.
|
||||
*/
|
||||
public class Log4j2OutputAppender {
|
||||
public static void append(StringBuilder toAppendTo){
|
||||
toAppendTo.append("TID: N/A");
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,6 @@ public class TraceIdConverter extends LogEventPatternConverter {
|
|||
|
||||
@Override
|
||||
public void format(LogEvent event, StringBuilder toAppendTo) {
|
||||
toAppendTo.append("TID: N/A");
|
||||
Log4j2OutputAppender.append(toAppendTo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.log4j.v2.x;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/12/7.
|
||||
*/
|
||||
public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "com.a.eye.skywalking.toolkit.log4j.v2.x.Log4j2OutputAppender";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
|
||||
return new StaticMethodsInterceptPoint[]{new StaticMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[]{new SimpleMethodMatcher("append")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.log4j.v2.x.PrintTraceIdInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,14 @@ package com.a.eye.skywalking.toolkit.activation.log4j.v2.x;
|
|||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.*;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/12/7.
|
||||
*/
|
||||
public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
public class PrintTraceIdInterceptor implements StaticMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
public void beforeMethod(StaticMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
((StringBuilder)interceptorContext.allArguments()[1]).append("TID:" + Tracing.getTraceId());
|
||||
|
||||
//make sure origin method do not invoke.
|
||||
|
|
@ -19,12 +17,12 @@ public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
public Object afterMethod(StaticMethodInvokeContext interceptorContext, Object ret) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
public void handleMethodException(Throwable t, MethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.log4j.v2.x;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/12/7.
|
||||
*/
|
||||
public class TraceIdConverterActivation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "com.a.eye.skywalking.toolkit.log4j.v2.x.TraceIdConverter";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public MethodMatcher[] getMethodsMatchers() {
|
||||
return new MethodMatcher[]{new SimpleMethodMatcher("format")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.log4j.v2.x.PrintTraceIdInterceptor";
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
com.a.eye.skywalking.toolkit.activation.log4j.v2.x.TraceIdConverterActivation
|
||||
com.a.eye.skywalking.toolkit.activation.log4j.v2.x.Log4j2OutputAppenderActivation
|
||||
|
|
|
|||
Loading…
Reference in New Issue