tags:

views:

72

answers:

1

I want to configure my log4j logging to not log messages that are 1) coming from a specific class and 2) of a specific severity i.e. WARN.

Can someone provide sample configuration/code on how to do this?

+1  A: 

The information below solves the problem for standart java.util.logging package:

For filtering classes you should implement Filter inteface and use it by calling setFilter method of Logger class:

public class ClassFilter implements Filter {
  public boolean isLoggable(LogRecord lr) {
    return (lr.getSourceClassName() == "SpecificClassName");
  }
}
...
Logger l = Logger.getLogger("mypackage.log");
l.setFilter(new ClassFilter());

For filtering severity use setLevel() method of Logger class.

Dmitry
Sorry, I was inattentive, this example uses standart java.util.logging package, not log4j. May be you will decide to switch to it from log4j :)
Dmitry