Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log 4j configuration for adding file name and line number

Tags:

java

log4j

I am using Log4j for logging my application activity. In my local environment it was logging like

Fiilename:linenumber: your logging message

then I created archive and deploy in another environment then its logging without file name, can any one clear me which property if logger do this. thanks

like image 764
Pedantic Avatar asked Oct 26 '25 01:10

Pedantic


2 Answers

In log4j.properties file set

log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %-5p %l - %m%n

Here %l specifies to generate the location information. According to the spec for PatternLayout : "The location information depends on the JVM implementation but usually consists of the fully qualified name of the calling method followed by the callers source the file name and line number between parentheses."

like image 150
Serge Rogatch Avatar answered Oct 28 '25 16:10

Serge Rogatch


Look at the documentation for PatternLayout. Note that figuring out file name and file number is slow (I guess it involves getting a stack trace and analyzing it).

like image 27
gpeche Avatar answered Oct 28 '25 16:10

gpeche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!