how can I disable output to log4j.rootLogger?

亡梦爱人 提交于 2019-12-05 01:51:54

You can use `log4j.additivity.FileLog = false, that is the 'flag' you are looking for.

From the official log4j documentation:

The output of a log statement of logger C will go to all the appenders in C and its ancestors. This is the meaning of the term "appender additivity".

However, if an ancestor of logger C, say P, has the additivity flag set to false, then C's output will be directed to all the appenders in C and its ancestors upto and including P but not the appenders in any of the ancestors of P.

Loggers have their additivity flag set to true by default.

Removing "stdout" from your root logger (as proposed in other answers) might not be a solution, because I suppose you are still interested in that console logs in some cases.

remove stdout from here

log4j.rootLogger=info,stdout

To:

log4j.rootLogger=info

I don't know the answer to the exact question the user provided, but facing a similar problem with the following log4j code:

log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n

I removed all logging lines from the console by changing

log4j.rootCategory=INFO, console

to

log4j.rootCategory=OFF, console

Remove "stdout" from root logger. It will stop writing on the console.

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