简体   繁体   English

如何在Log4J XML配置中禁用isInfoEnabled

[英]How to make isInfoEnabled disabled in Log4J XML configuration

I have various log files (debug, error) and different configurations (eg dev, prod). 我有各种日志文件(调试,错误)和不同的配置(例如dev,prod)。 In dev I'd like to have everything logged into my debug.log and errors written to error.log. 在开发中我想把所有内容都记录到我的debug.log中,并将错误写入error.log。 However in production I'd like to switch the debug logging off. 但是在生产中我想关闭调试日志。 Right now I'm using this config: 现在我正在使用这个配置:

<appender name="FileAppender" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="/logs/debug.log" />
    <param name="Append" value="true" />
    <param name="Threshold" value="OFF" />

... ...

So it will decide whether to write or not itself. 所以它将决定是否写自己。 But I'd like to check in the code sometimes, if the logger writes to log: 但是我有时会检查代码,如果记录器写入日志:

if(logger.isInfoEnabled()) {};

Even the threshold is set to 'OFF' it does says, that info is enabled. 即使阈值设置为'OFF',也就是说,该信息已启用。 What I'm trying to do is to configure the XML, so it would not only skip writing to the debug.log in the production, but also it would set the infoEnabled value to false, so I could use it in my code. 我正在尝试做的是配置XML,因此它不仅会跳过写入生产中的debug.log,而且还会将infoEnabled值设置为false,因此我可以在我的代码中使用它。 Is there are any possibilities to do that? 有没有可能做到这一点?

Thanks in advance! 提前致谢!

Configure your ROOT logger to 'WARN' level. 将ROOT记录器配置为“WARN”级别。 In Log4J 1.x: 在Log4J 1.x中:

<root>
    <level value="WARN" />
</root>

In Log4J 2.x: 在Log4J 2.x中:

<root level="WARN">
</root>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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