Bug 45147

Summary: Problem with conversion pattern. Line number not displayed correctly
Product: Log4j - Now in Jira Reporter: siva <sivaramans>
Component: LayoutAssignee: log4j-dev <log4j-dev>
Status: RESOLVED INVALID    
Severity: major CC: sivaramans
Priority: P2 Keywords: ErrorMessage
Version: 1.2   
Target Milestone: ---   
Hardware: Sun   
OS: Solaris   

Description siva 2008-06-05 23:18:32 UTC
Conversion pattern used - %d{yy-MM-dd HH:mm:ss}[%c{1}][%t][%L][%p]- %m%n

log output - 08-06-06 10:38:32[<class name>][Thread-31][?][INFO]- <Exception messsage>

Note that the line number in the log output is printed as "?". What is the reason for this?
Comment 1 Curt Arnold 2008-06-06 09:49:25 UTC
Possibly either class file was compiled without debug information or an AsyncAppender was used without setting locationInfo to true.  

However, the current approach depends on parsing the output of Throwable.printStackTrace and is susceptible to formatting issues.  There is an open enhancement request (Bug 45039) to use Throwable.getStackTrace() when running on JDK 1.4 and later.  If you think you are running into this type of issue, it would be helpful if you could single step through the LocationInformation constructor and report where the constructor bails out of parsing the output of printStackTrace. 
Comment 2 siva 2008-06-08 21:34:52 UTC
The following is my log4j properties file.

log4j.rootLogger=DEBUG,R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=<filePath>
log4j.appender.R.MaxFileSize=<fileSize>
log4j.appender.R.MaxBackupIndex=<No.OfBackups>
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%d{yy-MM-dd HH:mm:ss}[%c{1}][%t][%L][%p]- %m%n

The line number is displayed, if i launch the application from Eclipse. But, if i generate a build and launch the application, i get this problem with the line number.
Comment 3 Curt Arnold 2008-06-09 02:31:56 UTC
> But, if i generate a build and launch the application, i get this problem with the line number.

Sounds very much like you may have built your application without debugging info and there is no line numbers within the class file for log4j to extract.  If you are compiling with Sun's javac, did you specify -g to add debugging info?  If you build some other manner, did you specify that you wanted debugging information added to the class files.
Comment 4 siva 2008-06-09 03:38:45 UTC
I am using ANT script for compilation. I have added debug="ON" and this solved my problem. The doubt here is, won't javac, by default adds the line number information to the class file (http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html)

Anyway, thanks for the hint. I have fixed my problem. I am moving the bug to invalid state, since this has no relevance with the malfunctioning of log4j.