Example usage for java.util.logging ConsoleHandler setFilter

List of usage examples for java.util.logging ConsoleHandler setFilter

Introduction

In this page you can find the example usage for java.util.logging ConsoleHandler setFilter.

Prototype

public synchronized void setFilter(Filter newFilter) throws SecurityException 

Source Link

Document

Set a Filter to control output on this Handler .

Usage

From source file:fr.ippon.wip.util.WIPLogging.java

private WIPLogging() {
    try {/*from  w w  w  .ja v  a 2 s  .com*/
        // FileHandler launch an exception if parent path doesn't exist, so
        // we make sure it exists
        File logDirectory = new File(HOME + "/wip");
        if (!logDirectory.exists() || !logDirectory.isDirectory())
            logDirectory.mkdirs();

        accessFileHandler = new FileHandler("%h/wip/access.log", true);
        accessFileHandler.setLevel(Level.INFO);
        accessFileHandler.setFormatter(new SimpleFormatter());
        Logger.getLogger("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog").addHandler(accessFileHandler);

        ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setFilter(new Filter() {

            public boolean isLoggable(LogRecord record) {
                return !record.getLoggerName().equals("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog");
            }
        });

        Logger.getLogger("fr.ippon.wip").addHandler(consoleHandler);

        // For HttpClient debugging
        // FileHandler fileHandler = new
        // FileHandler("%h/wip/httpclient.log", true);
        // fileHandler.setLevel(Level.ALL);
        // Logger.getLogger("org.apache.http.headers").addHandler(fileHandler);
        // Logger.getLogger("org.apache.http.headers").setLevel(Level.ALL);

    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}