Example usage for java.util.logging Filter Filter

List of usage examples for java.util.logging Filter Filter

Introduction

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

Prototype

Filter

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    sendLogMessages();/*from  www.  j a  va 2s  .  co  m*/
    logger.setFilter(new Filter() {
        public boolean isLoggable(LogRecord record) {
            Object[] params = record.getParameters();
            if (params == null)
                return true;
            if (record.getParameters()[0] instanceof A)
                return true;
            return false;
        }
    });
    logger.info("After setting filter..");
    sendLogMessages();
}

From source file:SimpleFilter.java

public static void main(String[] args) {
    sendLogMessages();//from  ww w.  j  a v  a  2s .  c  o m
    logger.setFilter(new Filter() {
        public boolean isLoggable(LogRecord record) {
            Object[] params = record.getParameters();
            if (params == null)
                return true; // No parameters
            if (record.getParameters()[0] instanceof Duck)
                return true; // Only log Ducks
            return false;
        }
    });
    logger.info("After setting filter..");
    sendLogMessages();

}

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

private WIPLogging() {
    try {//from ww  w  .j a v a2 s. c om
        // 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();
    }
}

From source file:org.freaknet.gtrends.client.GoogleTrendsClientFactory.java

private static void setLogLevel(CmdLineParser cmdLine) throws SecurityException, IllegalArgumentException {
    final Level level;
    if (cmdLine.getLogLevel() != null) {
        level = Level.parse(cmdLine.getLogLevel());
    } else {/*from   ww w. j a  v  a 2s .c  o  m*/
        level = Level.parse(DEFAULT_LOGGING_LEVEL);
    }
    Logger log = LogManager.getLogManager().getLogger("");

    for (Handler h : log.getHandlers()) {
        log.removeHandler(h);
    }
    Handler handler = new ConsoleHandler();
    handler.setFormatter(new LogFormatter());
    handler.setLevel(level);
    log.setUseParentHandlers(false);

    Logger defaultLog = Logger.getLogger(GoogleConfigurator.getLoggerPrefix());
    defaultLog.addHandler(handler);
    defaultLog.setLevel(level);
    defaultLog.setFilter(new Filter() {
        @Override
        public boolean isLoggable(LogRecord record) {
            if (record.getSourceClassName().startsWith(GoogleConfigurator.getLoggerPrefix())) {
                return (record.getLevel().intValue() >= level.intValue());
            }
            return false;
        }
    });
}