On Dec 18, 2006, at 9:25 PM, jin xin wrote:

Hi:

I use the following code

Class testClass
{

public void test1()
{
---
Throwable throwable = null;
Throwable child = new Throwable("test");
LoggingEvent loggingEvent = new LoggingEvent(this.getClass().getName (),testLogger,Level.DEBUG,logMsg,child); System.out.println("class = "+loggingEvent.getLocationInformation ().getClassName()); System.out.println("method = "+loggingEvent.getLocationInformation ().getMethodName()); System.out.println("line = "+loggingEvent.getLocationInformation ().getLineNumber());---
---}
}
I am expecting to see the className, methodName and lineNumber to print out, however, I only get "?" for classNamem methodName and lineNumber.

Can anybody advise me what I did wrong?

Thanks

I see two potential usage errors. First, perhaps the caller was not compiled with debug information. In this case, you likely passed the "testClass" as the fully qualified logger name, so the reported location will be the location that called testClass.test1 and the test framework might not have been compiled with debugging info.

The second and less likely is that you extended testClass and the value of this.getClass().getName() isn't "testClass" but the name of the extended class, but the stack trace contains "testClass.test1" and log4j isn't able to determine the name of the caller. Using testClass.class.getName() would be better.

If you are still having problems, I'd suggest debugging into the getLocationInformation() call and see where things are breaking apart and if a resolution is not obvious, describe your observations and specify the version of log4j that you are using, the JVM in use, platform et al.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to