Search in sources :

Example 91 with Handler

use of java.util.logging.Handler in project simple-java by angryziber.

the class JavaUtilLoggerRedirector method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    // remove default handlers
    Logger rootLogger = LogManager.getLogManager().getLogger("");
    for (Handler handler : rootLogger.getHandlers()) {
        rootLogger.removeHandler(handler);
    }
    //        install redirecting handler
    SLF4JBridgeHandler.install();
}
Also used : Handler(java.util.logging.Handler) SLF4JBridgeHandler(org.slf4j.bridge.SLF4JBridgeHandler) Logger(java.util.logging.Logger)

Example 92 with Handler

use of java.util.logging.Handler in project gfm_viewer by satyagraha.

the class LogManager method configChanged.

@EventSubscriber(eventClass = Config.Changed.class)
public void configChanged(Config.Changed configChanged) {
    Level level = debugging || config.useEclipseConsole() ? Level.FINE : Level.INFO;
    logger.setLevel(level);
    if (consoleHandler == null) {
        consoleHandler = new ConsoleHandler();
        consoleHandler.setFormatter(formatter);
        logger.addHandler(consoleHandler);
    }
    if (logConsoleHandler == null && config.useEclipseConsole()) {
        LogConsole.start(GFM_CONSOLE);
        logConsoleHandler = LogConsole.getInstance().createHandler(formatter);
        logger.addHandler(logConsoleHandler);
    }
    for (Handler handler : logger.getHandlers()) {
        handler.setLevel(level);
    }
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Level(java.util.logging.Level) ConsoleHandler(java.util.logging.ConsoleHandler) EventSubscriber(org.bushe.swing.event.annotation.EventSubscriber)

Example 93 with Handler

use of java.util.logging.Handler in project mysql_perf_analyzer by yahoo.

the class MyPerfContext method configureLogging.

private void configureLogging() {
    Logger logger = Logger.getLogger("");
    try {
        logger.setLevel(Level.parse(getLogLevel()));
    } catch (Exception ex) {
        logger.setLevel(Level.INFO);
    }
    try {
        for (Handler h : logger.getHandlers()) {
            if (h instanceof java.util.logging.ConsoleHandler)
                h.setLevel(Level.SEVERE);
        }
        String logRoot = System.getProperty("logPath", ".");
        java.util.logging.FileHandler fileHandler = new java.util.logging.FileHandler(logRoot + File.separatorChar + getLogPath(), this.logFileSize, this.logFileCount);
        fileHandler.setLevel(logger.getLevel());
        fileHandler.setFormatter(new SimpleFormatter());
        logger.addHandler(fileHandler);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Example 94 with Handler

use of java.util.logging.Handler in project ACS by ACS-Community.

the class ClientLogManager method addRemoteHandler.

/**
     * Attaches a remote log handler to the given logger, if remote logging has not been suppressed.
     * 
     * Note that this method does not require <code>logger</code> to be 
     * already registered in {@linkplain #loggers}, but if it is, 
     * then the new AcsLoggingHandler is set in the map's AcsLoggerInfo as well.
     * 
     * @param logger  logger to be set up for remote logging
     * @return the remote handler that was added to the logger.
     */
private AcsLoggingHandler addRemoteHandler(AcsLogger logger) {
    AcsLoggingHandler remoteHandler = null;
    synchronized (loggers) {
        String loggerName = logger.getLoggerName();
        AcsLoggerInfo loggerInfo = loggers.get(loggerName);
        // logQueue == null serves as indicator for remote log suppression
        if (logQueue != null) {
            // try to find an existing handler 
            for (Handler handler : logger.getHandlers()) {
                if (handler instanceof AcsLoggingHandler) {
                    remoteHandler = (AcsLoggingHandler) handler;
                    if (loggerInfo != null && !remoteHandler.equals(loggerInfo.remoteHandler)) {
                        logger.info("Remote logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
                    }
                    break;
                }
            }
            if (remoteHandler == null) {
                // subscribes to sharedLogConfig
                remoteHandler = new AcsLoggingHandler(logQueue, sharedLogConfig, loggerName, logThrottle);
                logger.addHandler(remoteHandler);
                if (loggerInfo != null && loggerInfo.remoteHandler != null) {
                    logger.info("Logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
                }
            }
        }
        if (loggerInfo != null) {
            loggerInfo.remoteHandler = remoteHandler;
        }
    }
    return remoteHandler;
}
Also used : Handler(java.util.logging.Handler)

Example 95 with Handler

use of java.util.logging.Handler in project ACS by ACS-Community.

the class ClientLogManager method addLocalHandler.

/**
	 * Adds a local logging handler to the provided logger. Unlike with remote handlers in
	 * {@link #prepareRemoteLogging()}, for local handlers we don't allow removing and re-adding the handlers later.
	 * <p>
	 * Note that this method does not require <code>logger</code> to be already registered in {@linkplain #loggers}, but
	 * if it is, then the new StdOutConsoleHandler is set in the map's AcsLoggerInfo as well.
	 * 
	 * @param logger
	 *            logger to be set up for local logging
	 * @return the local handler that was added to the logger.
	 */
protected StdOutConsoleHandler addLocalHandler(AcsLogger logger) {
    StdOutConsoleHandler localHandler = null;
    synchronized (loggers) {
        String loggerName = logger.getLoggerName();
        AcsLoggerInfo loggerInfo = loggers.get(loggerName);
        // try to find an existing handler (should not happen)
        for (Handler handler : logger.getHandlers()) {
            if (handler instanceof StdOutConsoleHandler) {
                localHandler = (StdOutConsoleHandler) handler;
                if (loggerInfo != null && !localHandler.equals(loggerInfo.localHandler)) {
                    logger.info("Stdout logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
                }
                break;
            }
        }
        if (localHandler == null) {
            localHandler = createStdOutConsoleHandlerWithFormatter(sharedLogConfig, loggerName, logThrottle);
            logger.addHandler(localHandler);
            if (loggerInfo != null && loggerInfo.localHandler != null) {
                logger.info("Logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
            }
        }
        if (loggerInfo != null) {
            loggerInfo.localHandler = localHandler;
        }
    }
    return localHandler;
}
Also used : Handler(java.util.logging.Handler)

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