add toolkit of log4j, log4j2, logback and match toolkit-activation

This commit is contained in:
wusheng 2016-12-07 16:16:05 +08:00
parent dd7cce992d
commit 15b3add21b
20 changed files with 279 additions and 4 deletions

View File

@ -15,5 +15,7 @@
<modules>
<module>skywalking-toolkit-log4j-1.x</module>
<module>skywalking-toolkit-log4j-2.x</module>
<module>skywalking-toolkit-logback-1.x</module>
</modules>
</project>

View File

@ -1,4 +1,4 @@
package com.a.eye.skywalking.plugin.log.log4j.v1.x;
package com.a.eye.skywalking.toolkit.log.log4j.v1.x;
import org.apache.log4j.helpers.PatternConverter;
import org.apache.log4j.spi.LoggingEvent;

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skywalking-application-toolkit</artifactId>
<groupId>com.a.eye</groupId>
<version>2.0-2016</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skywalking-toolkit-log4j-2.x</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,34 @@
package com.a.eye.skywalking.toolkit.log4j.v2.x;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.pattern.ConverterKeys;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
/**
* Created by wusheng on 2016/12/7.
*/
@Plugin(name = "TraceIdConverter", category = "Converter")
@ConverterKeys({"tid"})
public class TraceIdConverter extends LogEventPatternConverter {
/**
* Constructs an instance of LoggingEventPatternConverter.
*
* @param name name of converter.
* @param style CSS style for output.
*/
protected TraceIdConverter(String name, String style) {
super(name, style);
}
public static TraceIdConverter newInstance(String[] options) {
return new TraceIdConverter("tid", "tid");
}
@Override
public void format(LogEvent event, StringBuilder toAppendTo) {
toAppendTo.append("TID: N/A");
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skywalking-application-toolkit</artifactId>
<groupId>com.a.eye</groupId>
<version>2.0-2016</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skywalking-toolkit-logback-1.x</artifactId>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
package com.a.eye.skywalking.toolkit.logback.v1.x;
import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
/**
* Created by wusheng on 2016/12/7.
*/
public class LogbackPatternConverter extends ClassicConverter {
@Override
public String convert(ILoggingEvent iLoggingEvent) {
return "TID: N/A";
}
}

View File

@ -0,0 +1,12 @@
package com.a.eye.skywalking.toolkit.logback.v1.x;
import ch.qos.logback.classic.PatternLayout;
/**
* Created by wusheng on 2016/12/7.
*/
public class TraceIdPatternLogbackLayout extends PatternLayout {
static {
defaultConverterMap.put("tid", LogbackPatternConverter.class.getName());
}
}

View File

@ -64,6 +64,11 @@
<artifactId>skywalking-toolkit-log4j-1.x-activation</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.a.eye</groupId>
<artifactId>skywalking-toolkit-log4j-2.x-activation</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>

View File

@ -11,6 +11,8 @@
<packaging>pom</packaging>
<modules>
<module>skywalking-toolkit-log4j-1.x-activation</module>
<module>skywalking-toolkit-log4j-2.x-activation</module>
<module>skywalking-toolkit-logback-1.x-activation</module>
</modules>
<artifactId>skywalking-toolkit-activation</artifactId>

View File

@ -12,7 +12,7 @@ import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine {
@Override
protected String enhanceClassName() {
return "com.a.eye.skywalking.plugin.log.log4j.v1.x.TraceIdPatternConverter";
return "com.a.eye.skywalking.toolkit.log.log4j.v1.x.TraceIdPatternConverter";
}
@Override

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skywalking-toolkit-activation</artifactId>
<groupId>com.a.eye</groupId>
<version>2.0-2016</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skywalking-toolkit-log4j-2.x-activation</artifactId>
</project>

View File

@ -0,0 +1,30 @@
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;
/**
* Created by wusheng on 2016/12/7.
*/
public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
((StringBuilder)interceptorContext.allArguments()[1]).append("TID:" + Tracing.getTraceId());
//make sure origin method do not invoke.
result.defineReturnValue(null);
}
@Override
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
return ret;
}
@Override
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
}
}

View File

@ -0,0 +1,37 @@
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";
}
}};
}
}

View File

@ -0,0 +1 @@
com.a.eye.skywalking.toolkit.activation.log4j.v2.x.TraceIdConverterActivation

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skywalking-toolkit-activation</artifactId>
<groupId>com.a.eye</groupId>
<version>2.0-2016</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skywalking-toolkit-logback-1.x-activation</artifactId>
</project>

View File

@ -0,0 +1,37 @@
package com.a.eye.skywalking.toolkit.activation.logback.v1.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 LogbackPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine {
@Override
protected String enhanceClassName() {
return "com.a.eye.skywalking.toolkit.logback.v1.x.LogbackPatternConverter";
}
@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return null;
}
@Override
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
@Override
public MethodMatcher[] getMethodsMatchers() {
return new MethodMatcher[]{new SimpleMethodMatcher("convert")};
}
@Override
public String getMethodsInterceptor() {
return "com.a.eye.skywalking.toolkit.activation.logback.v1.x.PrintTraceIdInterceptor";
}
}};
}
}

View File

@ -0,0 +1,27 @@
package com.a.eye.skywalking.toolkit.activation.logback.v1.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;
/**
* Created by wusheng on 2016/12/7.
*/
public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
}
@Override
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
return "TID:" + Tracing.getTraceId();
}
@Override
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
}
}

View File

@ -0,0 +1 @@
com.a.eye.skywalking.toolkit.activation.logback.v1.x.LogbackPatternConverterActivation