tags:

views:

603

answers:

2

Hi,

I used log4j to log some steps in my application. To be quick and dirty, I used:

org.apache.log4j.BasicConfigurator.configure();

This output my logs in the Eclipse console.

I want to know if and how to set the level threshold higher than DEBUG? In other word, I do not want to display DEBUG level message, just ERR, WARN, INFO.

Thank you.

EDIT: May I use this following?

import org.apache.log4j.Logger;
import org.apache.log4j.Level;
[...]
Logger logger = Logger.getLogger(this.class);
logger.setLevel(Level.INFO);
A: 

1) Find your appender, you sould have something like this in your log4j.xml configuration file.

    <appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
 <param name="File" value="C:/logs/rmDebug.log"/>
 <param name="Append" value="true"/>
 <param name="MaxFileSize" value="1500KB"/>
 <param name="MaxBackupIndex" value="2"/>
 <layout class="org.apache.log4j.PatternLayout">
  <param name="ConversionPattern" value="**FOOBAR** %d{dd.MM.yyyy HH:mm:ss} %c  %m%n"/>
 </layout>
 <filter class="org.apache.log4j.varia.LevelRangeFilter">
  <param name="LevelMin" value="DEBUG" />
  <param name="LevelMax" value="FATAL" />
 </filter>
</appender>

You see levelMin and LevelMax value ? levelMin is where you begin to log, and levelMax, where you stop to log. ( with this specific appender ). You can have several appender.

Then for assign this appender to a class or package. You can do something like that :

    <category name="com.foobar.automation.doremiResourceManager" additivity="true">
 <appender-ref ref="DEBUG"/>
</category>
Antoine Claval
That is the point: I do not want to bore me with a configuration file. Besides I knew about log4j.properties configuration file, but not about log4j.xml configuration file...
enguerran
A: 

I think the simplest way would be:

    Logger.getRootLogger().setLevel(Level.INFO);
Wolfgang
What is the difference betweenLogger.setLevel(...)andLogger.getRootLogger().setLevel(...)?
enguerran
Normally every class has ts own logger. These loggers form a hierarchy. The root logger is the special logger at the root of this hierarchy. Setting the level on the root logger affects all loggers (if not explicitly overridden). Setting the level on the logger of your class only affects log statements of your class.
Wolfgang