Search in sources :

Example 86 with Handler

use of java.util.logging.Handler in project Towny by ElgarL.

the class TownyLogger method CloseDownLogger.

public static void CloseDownLogger(Logger logger) {
    for (Handler fh : logger.getHandlers()) {
        logger.removeHandler(fh);
        fh.close();
    }
}
Also used : FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler)

Example 87 with Handler

use of java.util.logging.Handler in project CoreNLP by stanfordnlp.

the class JavaUtilLoggingAdaptor method adapt.

public static void adapt() {
    // get the top Logger:
    Logger topLogger = Logger.getLogger("");
    Handler oldConsoleHandler = null;
    // TODO confirm that this will always give us all handlers (i.e. do we need to loop over all Loggers in java.util.LogManager and do this for each one?)
    for (Handler handler : topLogger.getHandlers()) {
        if (handler instanceof ConsoleHandler && !(handler instanceof RedwoodHandler)) {
            // found the console handler
            oldConsoleHandler = handler;
            break;
        }
    }
    if (oldConsoleHandler != null) {
        // it's safe to call this after it's been removed
        topLogger.removeHandler(oldConsoleHandler);
    }
    if (!addedRedwoodHandler) {
        Handler redwoodHandler = new JavaUtilLoggingAdaptor.RedwoodHandler();
        topLogger.addHandler(redwoodHandler);
        addedRedwoodHandler = true;
    }
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 88 with Handler

use of java.util.logging.Handler in project CoreNLP by stanfordnlp.

the class MachineReading method setConsoleLevel.

public static void setConsoleLevel(Level level) {
    // get the top Logger:
    Logger topLogger = java.util.logging.Logger.getLogger("");
    // Handler for console (reuse it if it already exists)
    Handler consoleHandler = null;
    // see if there is already a console handler
    for (Handler handler : topLogger.getHandlers()) {
        if (handler instanceof ConsoleHandler) {
            // found the console handler
            consoleHandler = handler;
            break;
        }
    }
    if (consoleHandler == null) {
        // there was no console handler found, create a new one
        consoleHandler = new ConsoleHandler();
        topLogger.addHandler(consoleHandler);
    }
    // set the console handler level:
    consoleHandler.setLevel(level);
    consoleHandler.setFormatter(new SimpleFormatter());
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 89 with Handler

use of java.util.logging.Handler in project neo4j by neo4j.

the class SuppressOutput method java_util_logging.

public static Suppressible java_util_logging(final ByteArrayOutputStream redirectTo, Level level) {
    final Handler replacement = redirectTo == null ? null : new StreamHandler(redirectTo, new SimpleFormatter());
    if (replacement != null && level != null) {
        replacement.setLevel(level);
    }
    return new Suppressible() {

        @Override
        public Voice suppress() {
            final Logger logger = LogManager.getLogManager().getLogger("");
            final Level level = logger.getLevel();
            final Handler[] handlers = logger.getHandlers();
            for (Handler handler : handlers) {
                logger.removeHandler(handler);
            }
            if (replacement != null) {
                logger.addHandler(replacement);
                logger.setLevel(Level.ALL);
            }
            return new Voice(this, redirectTo) {

                @Override
                void restore(boolean failure) throws IOException {
                    for (Handler handler : handlers) {
                        logger.addHandler(handler);
                    }
                    logger.setLevel(level);
                    if (replacement != null) {
                        logger.removeHandler(replacement);
                    }
                }
            };
        }
    };
}
Also used : StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) StreamHandler(java.util.logging.StreamHandler) Handler(java.util.logging.Handler) Level(java.util.logging.Level) Logger(java.util.logging.Logger)

Example 90 with Handler

use of java.util.logging.Handler in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method bridgeHandlerInstalled.

private boolean bridgeHandlerInstalled() {
    Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
        if (handler instanceof SLF4JBridgeHandler) {
            return true;
        }
    }
    return false;
}
Also used : SLF4JBridgeHandler(org.slf4j.bridge.SLF4JBridgeHandler) SLF4JBridgeHandler(org.slf4j.bridge.SLF4JBridgeHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Aggregations

Handler (java.util.logging.Handler)135 Logger (java.util.logging.Logger)52 ConsoleHandler (java.util.logging.ConsoleHandler)30 LogRecord (java.util.logging.LogRecord)24 Test (org.junit.Test)22 FileHandler (java.util.logging.FileHandler)17 File (java.io.File)14 IOException (java.io.IOException)13 Level (java.util.logging.Level)11 SimpleFormatter (java.util.logging.SimpleFormatter)8 Formatter (java.util.logging.Formatter)7 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)5 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2