Pedantic
Pedantic

Reputation: 1378

Log 4j configuration for adding file name and line number

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

Upvotes: 4

Views: 8336

Answers (2)

Serge Rogatch
Serge Rogatch

Reputation: 15070

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."

Upvotes: 5

gpeche
gpeche

Reputation: 22514

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).

Upvotes: 3

Related Questions