Java logging:filters

Source: Internet
Author: User

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

Example of setting a on Filter 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 isLoggable() The method returns False, the is not LogRecord logged. If The method returns True, the is LogRecord forwarded to the Handler ' s of the given Logger .

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

public class Myfilter implements Filter {public    boolean isloggable (LogRecord record) {        return false;    }}

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

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

Java logging:filters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.