提交 15b3add2 编写于 作者: wu-sheng's avatar wu-sheng

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

上级 dd7cce99
......@@ -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>
<?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>
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");
}
}
<?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>
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";
}
}
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());
}
}
......@@ -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>
......
......@@ -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>
......
......@@ -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
......
<?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>
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) {
}
}
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";
}
}};
}
}
<?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>
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";
}
}};
}
}
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) {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册