Setting a Filter on a Logger Handler

A handler automatically filters messages based on a log level. For other types of filtering, you can set your own custom filter on a handler.
// Create a handler ConsoleHandler handler = new ConsoleHandler(); // Set the filter handler.setFilter(new Filter() { public boolean isLoggable(LogRecord record) { // return true if the record should be logged; // false otherwise. return true; } }); // Add the handler to a logger Logger logger = Logger.getLogger("com.mycompany"); logger.addHandler(handler);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.