LogbackPatternConverterActivation.java 2.1 KB
Newer Older
A
ascrutae 已提交
1
package com.a.eye.skywalking.toolkit.activation.log.logback.v1.x;
2 3 4

import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
5
import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint;
6
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
7 8 9 10
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

import static net.bytebuddy.matcher.ElementMatchers.named;
11 12

/**
13 14 15 16 17
 * Active the toolkit class "com.a.eye.skywalking.toolkit.log.logback.v1.x.LogbackPatternConverter".
 * Should not dependency or import any class in "skywalking-toolkit-logback-1.x" module.
 * Activation's classloader is diff from "com.a.eye.skywalking.toolkit.log.logback.v1.x.LogbackPatternConverter",
 * using direct will trigger classloader issue.
 * <p>
18 19 20
 * Created by wusheng on 2016/12/7.
 */
public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine {
21 22 23
    /**
     * @return the target class, which needs active.
     */
24 25
    @Override
    protected String enhanceClassName() {
A
ascrutae 已提交
26
        return "com.a.eye.skywalking.toolkit.log.logback.v1.x.LogbackPatternConverter";
27 28
    }

29 30 31
    /**
     * @return null, no need to intercept constructor of enhance class.
     */
32 33 34 35 36
    @Override
    protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
        return null;
    }

37 38 39
    /**
     * @return the collection of {@link StaticMethodsInterceptPoint}, represent the intercepted methods and their interceptors.
     */
40 41
    @Override
    protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
42
        return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
43
            @Override
44 45
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named("convert");
46 47 48 49
            }

            @Override
            public String getMethodsInterceptor() {
wu-sheng's avatar
wu-sheng 已提交
50
                return "com.a.eye.skywalking.toolkit.activation.log.logback.v1.x.PrintTraceIdInterceptor";
51 52 53 54
            }
        }};
    }
}