You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Ebersole, Steven" <st...@vignette.com> on 2002/06/27 18:22:10 UTC

LocationInfo bug

There is a real subtle bug in LocationInfo which can cause log4j itself to
skip stack frames.

It has to do with how the stack trace is searched.  In the current
LocationInfo.java at line 111, the following is executed:
    ibegin = s.lastIndexOf(fqnOfCallingClass);
where 'fqnOfCallingClass' is suppoed to be the Category or Logger or custom
wrapper initiating the logging event.

Now consider the following stack trace from my custom classes (made by
uncommenting line 101 in LocationInfo.java):
s is [java.lang.Exception
        at tests.misc.Logger.debug(Logger.java:51)
        at tests.misc.Logger.debug(Logger.java:46)
        at tests.misc.LoggerGenerator.main(LoggerGenerator.java:84)
].

In my custom classes, my wrapper is tests.misc.Logger so that initial search
(line 111) is really doing:
    ibegin = s.lastIndexOf( "tests.misc.Logger" );

Of course that also matches "tests.misc.LoggerGenerator" which is the last
line and so no location info is logged when I run this.


The simple work around I did was to modify line 111 as follows:
    ibegin = s.lastIndexOf( " " + fqnOfCallingClass + "." );

The leading space ensures that the above test would not also match
"my.tests.misc.Logger".



********************************************
Steve Ebersole
IT Integration Engineer
Vignette Corporation 
512.741.4195

Visit http://www.vignette.com

********************************************

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>