Log4j different appenders for different log levels using properties file

余生颓废 提交于 2019-11-30 11:50:12

问题


Since the official documentation for log4j is a broken link, and the getting started guide isn't helping me, I would like to know how to use two appenders with different log levels for the same logger, using a .properties file instead of an .xml one.

For example, like this:

log4j.rootLogger=debug,  APPENDER_FILE, APPENDER_STDOUT

I'm logging with two different appenders, but on the same log level (DEBUG). I would like to use an INFO log level for APPENDER_STDOUT, and aDEBUG log level for APPENDER_FILE.

My question is similar to this, but unlike that question, I'm using the log4j.properties file, not the xml file.


回答1:


You need to set the logger to the more detailed of the two levels (DEBUG) but then set a threshold on the appender to tell it to only show messages at INFO and above

log4j.appender.APPENDER_STDOUT.Threshold=INFO



回答2:


Also, if you want to specify the appender at the package level, you can use:

log4j.logger.[package]=[Level], [Appender]

Example:

log4j.logger.org.apache.cxf=INFO, MyAppender

For more details, please, take a look at: https://stackoverflow.com/a/19795886/679240



来源:https://stackoverflow.com/questions/12619754/log4j-different-appenders-for-different-log-levels-using-properties-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!