Skip to content

Commit

Permalink
[pinpoint-apm#2862] Remove code using annotation logic in log4j, logb…
Browse files Browse the repository at this point in the history
…ack plugin
  • Loading branch information
minwoo-jung committed Apr 26, 2017
1 parent 7066ef6 commit 1770c4f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,20 @@ public static void addInterceptor(InstrumentClass clazz, String methodName, Stri
}
method.addScopedInterceptor(interceptorClassName, interceptorParams, scopeName, executionPolicy);
}

public static void addInterceptorToConstructor(InstrumentClass clazz, String[] parameterTypes, String interceptorClassName) throws InstrumentException {
if (clazz == null) {
throw new NullPointerException("clazz must not be null");
}
if (interceptorClassName == null) {
throw new NullPointerException("interceptorClassName must not be null");
}

InstrumentMethod constructor = clazz.getConstructor(parameterTypes);
if (constructor == null) {
throw new NotFoundInstrumentException("Cannot find constructor with parameter types: " + Arrays.toString(parameterTypes));
}

constructor.addInterceptor(interceptorClassName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException;
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod;
import com.navercorp.pinpoint.bootstrap.instrument.Instrumentor;
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback;
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
Expand All @@ -27,6 +28,7 @@
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;
import com.navercorp.pinpoint.bootstrap.plugin.util.InstrumentUtils;

/**
* This modifier support log4j 1.2.15 version, or greater.
Expand All @@ -41,7 +43,7 @@ public class Log4jPlugin implements ProfilerPlugin, TransformTemplateAware {
private final PLogger logger = PLoggerFactory.getLogger(getClass());
private TransformTemplate transformTemplate;


@Override
public void setup(ProfilerPluginSetupContext context) {
final Log4jConfig config = new Log4jConfig(context.getConfig());
Expand Down Expand Up @@ -94,9 +96,12 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, Strin
+ "\nconstructor prototype : LoggingEvent(final String fqnOfCategoryClass, final Category logger, final long timeStamp, final Level level, final Object message, final String threadName, final ThrowableInformation throwable, final String ndc, final LocationInfo info, final java.util.Map properties);");
return null;
}

target.addInterceptor("com.navercorp.pinpoint.plugin.log4j.interceptor.LoggingEventOfLog4jInterceptor");


final String interceptorClassName = "com.navercorp.pinpoint.plugin.log4j.interceptor.LoggingEventOfLog4jInterceptor";
InstrumentUtils.addInterceptorToConstructor(target, new String[]{"java.lang.String", "org.apache.log4j.Category", "org.apache.log4j.Priority", "java.lang.Object", "java.lang.Throwable"}, interceptorClassName);
InstrumentUtils.addInterceptorToConstructor(target, new String[]{"java.lang.String", "org.apache.log4j.Category", "long", "org.apache.log4j.Priority", "java.lang.Object", "java.lang.Throwable"}, interceptorClassName);
InstrumentUtils.addInterceptorToConstructor(target, new String[]{"java.lang.String", "org.apache.log4j.Category", "long", "org.apache.log4j.Level", "java.lang.Object", "java.lang.String", "org.apache.log4j.spi.ThrowableInformation", "java.lang.String", "org.apache.log4j.spi.LocationInfo", "java.util.Map"}, interceptorClassName);

return target.toBytecode();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException;
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod;
import com.navercorp.pinpoint.bootstrap.instrument.Instrumentor;
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback;
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
Expand All @@ -27,6 +28,7 @@
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;
import com.navercorp.pinpoint.bootstrap.plugin.util.InstrumentUtils;

/**
* This modifier support slf4j 1.4.1 version and logback 0.9.8 version, or greater.
Expand Down Expand Up @@ -87,9 +89,11 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, Strin
+ "\nconstructor prototype : LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray);");
return null;
}

target.addInterceptor("com.navercorp.pinpoint.plugin.logback.interceptor.LoggingEventOfLogbackInterceptor");


final String interceptorClassName = "com.navercorp.pinpoint.plugin.log4j.interceptor.LoggingEventOfLog4jInterceptor";
InstrumentUtils.addInterceptorToConstructor(target, new String[0], interceptorClassName);
InstrumentUtils.addInterceptorToConstructor(target, new String[]{"java.lang.String", "ch.qos.logback.classic.Logger", "ch.qos.logback.classic.Level", "java.lang.String", "java.lang.Throwable", "java.lang.Object[]"}, interceptorClassName);

return target.toBytecode();
}
});
Expand Down

0 comments on commit 1770c4f

Please sign in to comment.