tags:

views:

20

answers:

2

I am using log4j for traces.

I am using the following pattern for my trace:

<layout class="org.apache.log4j.PatternLayout">
  <param name="ConversionPattern" value="%d{dd-MM HH:mm:ss.SSS} | %X{sid} | [%t] | %F:%M:%L | %-5p | %m%n"/>
</layout>


In some classes I expect to get:

[11/4/09 17:03:57:160 IST] 00000012 SystemOut O 04-11 17:03:57.144 | | [server.startup : 0] | MainServlet.java:init:79 | DEBUG | Test Debug

I get wrong source code location:

[11/4/09 17:03:57:160 IST] 00000012 SystemOut O 04-11 17:03:57.144 | | [server.startup : 0] | ?:init:? | DEBUG | Test Debug

In some other classes I get correct source location.

What am I doing wrong?

+1  A: 

Perhaps some of your classes are compiled wíthout line information? If you add the "optimization" option -O to javac it will strip line numbers.

Martin
A: 

Are you initializing your logger in those problem classes or inheriting it? For example, do you have a line similar to this one:

protected final Log logger = LogFactory.getLog(getClass());
Chris J