Pregunta

I have various log files (debug, error) and different configurations (e.g. dev, prod). In dev I'd like to have everything logged into my debug.log and errors written to 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. 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. Is there are any possibilities to do that?

Thanks in advance!

¿Fue útil?

Solución

Configure your ROOT logger to 'WARN' level. In Log4J 1.x:

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

In Log4J 2.x:

<root level="WARN">
</root>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top