[slf4j-dev] svn commit: r1234 - in slf4j/trunk: slf4j-ext/src/main/java/org/slf4j/instrumentation slf4j-site/src/site/pages
ravn at slf4j.org
ravn at slf4j.org
Sat Nov 15 00:09:36 CET 2008
Author: ravn
Date: Sat Nov 15 00:09:36 2008
New Revision: 1234
Modified:
slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java
slf4j/trunk/slf4j-site/src/site/pages/extensions.html
Log:
added note on static logger name and that empty methods are not logged
Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java (original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java Sat Nov 15 00:09:36 2008
@@ -135,8 +135,6 @@
+ builder.level.substring(1) + "Enabled";
}
- private static final String _LOG = "_log";
-
private boolean addEntryExit;
// private boolean addVariableAssignment;
private boolean verbose;
@@ -176,6 +174,8 @@
return doClass(className, clazz, bytes);
}
+ private String loggerName;
+
/**
* doClass() process a single class by first creates a class description from
* the byte codes. If it is a class (i.e. not an interface) the methods
@@ -196,12 +196,16 @@
cl = pool.makeClass(new ByteArrayInputStream(b));
if (cl.isInterface() == false) {
- // We have to define the log variable.
+ loggerName = "_____log";
+
+ // We have to declare the log variable.
+
String pattern1 = "private static org.slf4j.Logger {};";
- String loggerDefinition = format(pattern1, _LOG);
+ String loggerDefinition = format(pattern1, loggerName);
CtField field = CtField.make(loggerDefinition, cl);
// and assign it the appropriate value.
+
String pattern2 = "org.slf4j.LoggerFactory.getLogger({}.class);";
String replace = name.replace('/', '.');
String getLogger = format(pattern2, replace);
@@ -210,6 +214,8 @@
// then check every behaviour (which includes methods). We are only
// interested in non-empty ones, as they have code.
+ // NOTE: This will be changed, as empty methods should be
+ // instrumented too.
CtBehavior[] methods = cl.getDeclaredBehaviors();
for (int i = 0; i < methods.length; i++) {
@@ -247,13 +253,13 @@
if (addEntryExit) {
String messagePattern = "if ({}.{}()) {}.{}(\">> {}\");";
- Object[] arg1 = new Object[] { _LOG, levelEnabled, _LOG, level, signature };
+ Object[] arg1 = new Object[] { loggerName, levelEnabled, loggerName, level, signature };
String before = MessageFormatter.arrayFormat(messagePattern, arg1);
// System.out.println(before);
method.insertBefore(before);
String messagePattern2 = "if ({}.{}()) {}.{}(\"<< {}{}\");";
- Object[] arg2 = new Object[] { _LOG, levelEnabled, _LOG, level,
+ Object[] arg2 = new Object[] { loggerName, levelEnabled, loggerName, level,
signature, returnValue };
String after = MessageFormatter.arrayFormat(messagePattern2, arg2);
// System.out.println(after);
Modified: slf4j/trunk/slf4j-site/src/site/pages/extensions.html
==============================================================================
--- slf4j/trunk/slf4j-site/src/site/pages/extensions.html (original)
+++ slf4j/trunk/slf4j-site/src/site/pages/extensions.html Sat Nov 15 00:09:36 2008
@@ -690,6 +690,11 @@
printed, are silently swallowed by the JVM.</li>
<li>The javaagent does not do any logging itself, and the slf4j
backend does not need to be available to the agent. </li>
+ <li>The name of the logger variable is fixed (to a value unlikely to be used) so if that
+ name is already used, a failure occures. This should be changed to determine
+ an unused name and use that instead.</li>
+ <li>Empty methods are not instrumented (an incorrect check for an interface). They should be</li>
+
</ul>
<p>(The agent is an adaption of the java.util.logging version
More information about the slf4j-dev
mailing list