0

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!

psisoyev
  • 2,118
  • 1
  • 25
  • 35

1 Answers1

2

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

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

In Log4J 2.x:

<root level="WARN">
</root>
Thomas W
  • 13,940
  • 4
  • 58
  • 76
  • But in that case all my other appenders won't write as well, right? As I said, I have few files to write. Like debug.log, error.log, foo.log, bar.log. In last two logger level should be DEBUG. Or I'm wrong? – psisoyev May 09 '13 at 08:16
  • You said you wanted INFO disabled -- which would imply logging at that level is skipped, and never gets sent to any Appenders! That's what you asked about. Threshold limits a specific appender, Logger/Category level controls the enablement level of those categories. – Thomas W May 09 '13 at 08:19
  • Perhaps you want a combination of Logger Levels and Appender Thresholds -- but I've given you the correct answer to your actual question. – Thomas W May 09 '13 at 08:20
  • I agree with you. Thanks! I think I will use different categories as well. – psisoyev May 09 '13 at 08:22