简体   繁体   中英

How to make log4j print origin of message?

Is there a way to make Log4j-outputs include the origin of the message? The following configuration via log4j.properties (which has been handed over to me...):

log4j.rootCategory=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p - %m%n

fails to print out the very important detail of what class is sending that message, and right now I could really need that bit on info!

Layna

See Conversion Pattern Layout

For example, you can use ConversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n

If you use the %C notation, you can see the package and the class name of the log origin.

So, you can use:

log4j.rootCategory=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p - %m%n - %C

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM