diff --git a/skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log4j/v2/x/Log4j2OutputAppender.java b/skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log4j/v2/x/Log4j2OutputAppender.java new file mode 100644 index 0000000000000000000000000000000000000000..890df092d2d032274d01e16567352abbdc00c64a --- /dev/null +++ b/skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log4j/v2/x/Log4j2OutputAppender.java @@ -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"); + } +} diff --git a/skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log4j/v2/x/TraceIdConverter.java b/skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log4j/v2/x/TraceIdConverter.java index f01726bc0cb425c4754754b16a0ab998c68ce378..046081eef4d0570ca1184d65cc797070741b6cc5 100644 --- a/skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log4j/v2/x/TraceIdConverter.java +++ b/skywalking-application-toolkit/skywalking-toolkit-log4j-2.x/src/main/java/com/a/eye/skywalking/toolkit/log4j/v2/x/TraceIdConverter.java @@ -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); } } diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/Log4j2OutputAppenderActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/Log4j2OutputAppenderActivation.java new file mode 100644 index 0000000000000000000000000000000000000000..4a99f4bcfe5f0caf6c169883d986adbe16cb621c --- /dev/null +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/Log4j2OutputAppenderActivation.java @@ -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"; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/PrintTraceIdInterceptor.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/PrintTraceIdInterceptor.java index 3aee17f0b30750f029e916b432c71fa520613ade..6fd22bcc5cdd23c7d24838c2486fed6ba17d8bcf 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/PrintTraceIdInterceptor.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/PrintTraceIdInterceptor.java @@ -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) { } } diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/TraceIdConverterActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/TraceIdConverterActivation.java deleted file mode 100644 index 233ae4f4a33d9f7cba62a526215ea52a332bbbfe..0000000000000000000000000000000000000000 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log4j/v2/x/TraceIdConverterActivation.java +++ /dev/null @@ -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"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def index bba23263ec18a8cbf0452029f58abe323d31762c..8fc2dd7501e85df77fe15172e0e50828b3952dba 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-log4j-2.x-activation/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -com.a.eye.skywalking.toolkit.activation.log4j.v2.x.TraceIdConverterActivation +com.a.eye.skywalking.toolkit.activation.log4j.v2.x.Log4j2OutputAppenderActivation