开发者

Log4j: How filter out messages from a specific class?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜