Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

log4j not printing filename and line number in log file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks,
Krishna
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And by the way, which version and vendor of Java do you use to compile and to run the application?
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i think you should look at PtternLayout Documentation.

i found this there .

F: Used to output the file name where the logging request was issued.

WARNING Generating caller location information is extremely slow. It's use should be avoided unless execution speed is not an issue.

L: Used to output the line number from where the logging request was issued.

WARNING Generating caller location information is extremely slow. It's use should be avoided unless execution speed is not an issue.

SO.

might be its a problem of execution speed.

think about it ...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Johnson and welcome to Javaranch!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

if you still insist to use asyncappender
here is the solution i got from: http://marc.info/?l=log4j-user&m=105581147910000&w=2

<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="256"/>
<param name="LocationInfo" value="true"/>
</appender>

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

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread is still useful .
Resolved my problem.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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??

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thanks Johnson..it's working now..
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Kumar wrote:
Thanks Johnson!! , is it because that by setting debug to true the values will be passed to compilers??



As per the documentation of Ant javac task

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.

 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic