Search in sources :

Example 1 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project syncany by syncany.

the class CommandLineClient method initLogHandlers.

private void initLogHandlers(OptionSet options, OptionSpec<String> optionLog, OptionSpec<Void> optionLogPrint, OptionSpec<Void> optionDebug) throws SecurityException, IOException {
    // --log=<file>
    String logFilePattern = null;
    if (options.has(optionLog)) {
        if (!"-".equals(options.valueOf(optionLog))) {
            logFilePattern = options.valueOf(optionLog);
        }
    } else if (config != null && config.getLogDir().exists()) {
        logFilePattern = config.getLogDir() + File.separator + LOG_FILE_PATTERN;
    } else {
        logFilePattern = UserConfig.getUserLogDir() + File.separator + LOG_FILE_PATTERN;
    }
    if (logFilePattern != null) {
        Handler fileLogHandler = new FileHandler(logFilePattern, LOG_FILE_LIMIT, LOG_FILE_COUNT, true);
        fileLogHandler.setFormatter(new LogFormatter());
        Logging.addGlobalHandler(fileLogHandler);
    }
    // --debug, add console handler
    if (options.has(optionDebug) || options.has(optionLogPrint) || (options.has(optionLog) && "-".equals(options.valueOf(optionLog)))) {
        Handler consoleLogHandler = new ConsoleHandler();
        consoleLogHandler.setFormatter(new LogFormatter());
        Logging.addGlobalHandler(consoleLogHandler);
    }
}
Also used : FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) ConsoleHandler(java.util.logging.ConsoleHandler) LogFormatter(org.syncany.config.LogFormatter) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler)

Example 2 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project commons by twitter.

the class RootLogConfig method setConsoleHandler.

private static void setConsoleHandler(Logger logger, boolean removeOtherHandlers) {
    Handler consoleHandler = null;
    for (Handler h : logger.getHandlers()) {
        if (h instanceof ConsoleHandler) {
            consoleHandler = h;
        } else if (removeOtherHandlers) {
            logger.removeHandler(h);
        }
    }
    if (consoleHandler == null) {
        consoleHandler = new ConsoleHandler();
        logger.addHandler(new ConsoleHandler());
    }
    consoleHandler.setLevel(Level.ALL);
    consoleHandler.setFilter(null);
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 3 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project reversehttp by tonyg.

the class TestNormalHttpService method configureLogging.

private static void configureLogging() {
    ConsoleHandler handler = new ConsoleHandler();
    Logger root = Logger.getLogger("");
    root.addHandler(handler);
    handler.setLevel(Level.FINER);
    root.setLevel(Level.FINER);
}
Also used : Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 4 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project reversehttp by tonyg.

the class TestReverseHttpService method configureLogging.

private static void configureLogging() {
    ConsoleHandler handler = new ConsoleHandler();
    Logger root = Logger.getLogger("");
    root.addHandler(handler);
// handler.setLevel(Level.FINER);
// root.setLevel(Level.FINER);
}
Also used : Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 5 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class LogManagerTest method testReset.

public void testReset() throws SecurityException, IOException {
    // mock LogManager
    mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    assertNotNull(mockManager.getProperty("handlers"));
    Logger foo = new MockLogger(FOO, null);
    assertNull(foo.getLevel());
    assertEquals(0, foo.getHandlers().length);
    foo.setLevel(Level.ALL);
    foo.addHandler(new ConsoleHandler());
    assertTrue(mockManager.addLogger(foo));
    assertEquals(Level.WARNING, foo.getLevel());
    assertEquals(2, foo.getHandlers().length);
    // reset
    mockManager.reset();
    // properties is cleared
    assertNull(mockManager.getProperty("handlers"));
    // level is null
    assertNull(foo.getLevel());
    // handlers are all closed
    assertEquals(0, foo.getHandlers().length);
    // for root logger
    manager.reset();
    assertNull(manager.getProperty("handlers"));
    Logger root = manager.getLogger("");
    // level reset to info
    assertEquals(Level.INFO, root.getLevel());
    // also close root's handler
    assertEquals(0, root.getHandlers().length);
}
Also used : Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)49 Handler (java.util.logging.Handler)19 Logger (java.util.logging.Logger)15 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)5 PrintStream (java.io.PrintStream)5 FileHandler (java.util.logging.FileHandler)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Formatter (java.util.logging.Formatter)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 Rectangle (java.awt.Rectangle)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1