简体   繁体   中英

Log4j | Updating the Log Level for the Appender

My log4j.properties file -

log4j.rootLogger=INFO, stdout

# =============== console output appender =====================
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %5p: [%c{1}] %m%n

# =================== common logging =========================
# The log level for all classes that are not configured below.
log4j.logger.petascope=INFO

log4j.logger.petascope.wcps=DEBUG
log4j.logger.petascope.wcst=DEBUG
log4j.logger.petascope.wcs=DEBUG
log4j.logger.petascope.wcs2=TRACE

I want to display even DEBUG and TRACE messages on stdout, so I changed the following line

   log4j.rootLogger=TRACE, stdout

But I don't see any changes when I view the logs echoes on Tomcat Console, I still see only INFO, WARN ... messages.

Well, even if you have your root logger as TRACE, your log4j.logger.petascope (pointing to INFO) will override the default root logger's TRACE for petascope.* packages, which is the reason you are not seeing any DEBUG and TRACE.

To keep things simple, try this... set the root logger to trace:-

log4j.rootLogger=TRACE, stdout

Then, comment out the following lines:-

#log4j.logger.petascope=INFO
#log4j.logger.petascope.wcps=DEBUG
#log4j.logger.petascope.wcst=DEBUG
#log4j.logger.petascope.wcs=DEBUG
#log4j.logger.petascope.wcs2=TRACE

Let me know if that works for you.

Try this:

log4j.appender.stdout.Threshold=TRACE

(as described in another StackOverflow question ).

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