• Java Logging: Filters


     

    You can set a Filter on a Logger. A Filter can filter out log messages, meaning decide if the message gets logged or not. Filters are represented by the Java interface java.util.logging.Filter

    Here is an example of setting a Filter on a Logger:

    Filter filter = new MyFilter();
    
    logger1.setFilter(filter);
    

    The Filter interface is defined like this:

    public interface Filter {
        public boolean isLoggable(LogRecord record);
    }
    

    If the isLoggable() method returns false, the LogRecord is not logged. If the method returns true, theLogRecord is forwarded to the Handler's of the given Logger.

    To create a Filter you must implement that interface. Here is a very simple example implementation:

    public class MyFilter implements Filter {
        public boolean isLoggable(LogRecord record) {
            return false;
        }
    }
    

    This filter rejects all messages. Of course this is not a very useful filter. You would probably inspect the LogRecordand make a decision based on that. You can learn more about the LogRecord in the text on the LogRecord, and in the JavaDoc too.

    For a discussion of how Filter's work within the Logger hierarchy, see the text on the Logger hierarchy.

  • 相关阅读:
    [状压DP][二分]JZOJ 3521 道路覆盖
    字符串操作
    练习: 判断一个数是否为小数
    Python 深浅拷贝
    编码
    python中的 == 和 is 的区别
    Python3 字典的增删改查
    Python3 列表的基本操作
    初识 Python
    方法的入门
  • 原文地址:https://www.cnblogs.com/hephec/p/4579626.html
Copyright © 2020-2023  润新知