[slf4j-dev] [Bug 13] JDK14LoggerAdapter does not preserve source class name

bugzilla-daemon at gil.qos.ch bugzilla-daemon at gil.qos.ch
Fri Jan 27 10:58:01 CET 2006


http://bugzilla.slf4j.org/show_bug.cgi?id=13





------- Additional Comments From boris.unckel.mlg at gmx.net  2006-01-27 10:58 -------
(In reply to comment #3)
> My patch does not introduce any extra CPU overhead, since when the logger
> source class is provided in a 
> LogRecord, the JDK implementation does attempt to determine it on its own.

The patch you have provided forces the wrapper class to create a Throwable for
each call to log. (private void determineSource( LogRecord record ) {...})
I have provided a copy of the source which is used by the jdk. The String of the
source class is hardcoded. setLoggerName is not responsible for determination of
LocationInformation. You simply do not have a chance to change this until you
provide your own "MyLogRecord extends LogRecord" class.

If the correspondend formatter configured in java.util.logging does not print
out LocationInformation (either as PatternFormatter or as hardcoded
MyFormatter), you will have overhead per log call.

My -1 for applying this patch.

Use slf4j with x4juli if you want to have LocationInformation AND
java.util.logging AND overhead when overhead is necessary and configured.

By the way JCL suffers from the same problem:
http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/Jdk14Logger.java?view=markup
See private void log( Level level, String msg, Throwable ex ) {...}


Copy from java.util.logging.LogRecord
    // Private method to infer the caller's class and method names
    private void inferCaller() {
	needToInferCaller = false;
	// Get the stack trace.
	StackTraceElement stack[] = (new Throwable()).getStackTrace();
	// First, search back to a method in the Logger class.
	int ix = 0;
	while (ix < stack.length) {
	    StackTraceElement frame = stack[ix];
	    String cname = frame.getClassName();
	    if (cname.equals("java.util.logging.Logger")) {
		break;
	    }
	    ix++;
	}
	// Now search for the first frame before the "Logger" class.
	while (ix < stack.length) {
	    StackTraceElement frame = stack[ix];
	    String cname = frame.getClassName();
	    if (!cname.equals("java.util.logging.Logger")) {
		// We've found the relevant frame.
	        setSourceClassName(cname);
	        setSourceMethodName(frame.getMethodName());
		return;
	    }
	    ix++;
	}
	// We haven't found a suitable frame, so just punt.  This is
        // OK as we are only commited to making a "best effort" here.
    }

-- 
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the slf4j-dev mailing list