如何禁用log4j.rootLogger的输出? [英] how can I disable output to log4j.rootLogger?

查看:932
本文介绍了如何禁用log4j.rootLogger的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在登录文件时禁用输出到控制台。请参阅下面的配置文件:

I want to disable the output to the console when logging to file. See config-file below:

log4j.rootLogger=info,stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L --- %m%n

log4j.category.FileLog=info,R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=E:\\temp\\FileLog
log4j.appender.R.Append = true
log4j.appender.R.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.R.layout=org.apache.log4j.PatternLayout  
log4j.appender.R.layout.ConversionPattern=%m[%d{MM-dd HH:mm:ss}]%n

当我使用时:

Logger.getLogger("FileLog").info("LogText-FileLog");

此日志打印到 stdout 也是如何我可以禁用它吗?

this log print to stdout too,how can I disable it?

推荐答案

你可以使用`log4j.additivity.FileLog = false,那就是'标志'你是寻找。

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

来自官方log4j文档


记录器C的日志语句的输出将转到C及其祖先的所有appender
。这就是术语appender
additivity的含义。

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

但是,如果记录器C的祖先,比如P,则具有
加法性flag设置为false,然后C的输出将被定向到C中的appenders及其祖先的所有
,包括P但不包括P的任何祖先中的
appenders。

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.

记录器默认情况下将其可加性标志设置为true。

Loggers have their additivity flag set to true by default.

从根目录中删除stdout logger(在其他答案中提出)可能不是解决方案,因为我认为在某些情况下你仍然对该控制台日志感兴趣。

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.

这篇关于如何禁用log4j.rootLogger的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆