Setting a Filter on a Logger Handler : Log Filter « Log « Java Tutorial






import java.util.logging.ConsoleHandler;
import java.util.logging.Filter;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

public class Main {
  public static void main(String[] argv) throws Exception {
    ConsoleHandler handler = new ConsoleHandler();

    handler.setFilter(new Filter() {
      public boolean isLoggable(LogRecord record) {
       return true;
      }
    });

    // Add the handler to a logger
    Logger logger = Logger.getLogger("com.mycompany");
    logger.addHandler(handler);
  }
}








35.3.Log Filter
35.3.1.Simple filter
35.3.2.Setting a Filter on a Logger Handler
35.3.3.Custom filter