Bug 45147 - Problem with conversion pattern. Line number not displayed correctly
Summary: Problem with conversion pattern. Line number not displayed correctly
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Layout (show other bugs)
Version: 1.2
Hardware: Sun Solaris
: P2 major
Target Milestone: ---
Assignee: log4j-dev
Keywords: ErrorMessage
Depends on:
Reported: 2008-06-05 23:18 UTC by siva
Modified: 2008-06-09 03:38 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
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.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.