Hi all, I am facing a problem printing filename and line number in log file using log4j. When I am try this from eclipse its working perfectly. When I am creating a jar of my standalone application using Ant and try to running it form Jar then it is printing (?:?) in place of filename and line number.
Here is my log4j.xml
the log output 1. Run application from eclipse
2. Run from Jar
I am using Spring IOC. Surpricingly spring related logging priting the filename and line numbers in the console even when I run it from Jar.
I found same problem in one of our forums but did not get solution for it. Can anybody please help me out.
The line numbers and filename are available only if you compiled the java files with -g enabled (which by the way is the default). See this for more details (look for the -g option there).
anybody ever come up with a solution to this problem? I'm running into the same thing. The -g option will add to default debugging info, but the default setting is class and line numbers anyway. from javac compiler reference Generate all debugging information, including local variables. By default, only line number and source file information is generated.
I guess you must compile the jar with ant,by default,ant do not enable debug,so you can get neither FILENAME nor LINE NUMBER,just enable debug by add debug = true while compiling,for example:
<javac destdir="XXXX" source="1.5" target="1.5" debug="true" encoding="UTF-8">
i'm having this kind of issue is because i'm using org.apache.log4j.AsyncAppender
if i change back to use org.apache.log4j.rolling.RollingFileAppender
it was working perfect and sweet.
after add in <param name="LocationInfo" value="true"/>
you'll get the filename and linenumber appear correctly.
Krishna Chaithanya dhulipala wrote:Hi all,
I am facing a problem printing filename and line number in log file using log4j.
When I am try this from eclipse its working perfectly. When I am creating a jar of my standalone application using Ant and try to running it form Jar then it is printing (?:?) in place of filename and line number.
Krishna
johnson hong wrote:I guess you must compile the jar with ant,by default,ant do not enable debug,so you can get neither FILENAME nor LINE NUMBER,just enable debug by add debug = true while compiling,for example:
<javac destdir="XXXX" source="1.5" target="1.5" debug="true" encoding="UTF-8">
enabling debug to true worked for me!!! Thanks Johnson!! , is it because that by setting debug to true the values will be passed to compilers??
debug - Indicates whether source should be compiled with debug information; defaults to off. If set to off, -g:none will be passed on the command line for compilers that support it (for other compilers, no command line argument will be used). If set to true, the value of the debuglevel attribute determines the command line argument.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: log4j not printing filename and line number in log file