Search in sources :

Example 36 with ConsoleHandler

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

the class ConsoleHandlerTest method testPublish_EmptyMsg.

/*
	 * Test publish(), a log record with empty msg, having output stream
	 */
public void testPublish_EmptyMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    LogRecord r = new LogRecord(Level.INFO, "");
    h.publish(r);
    h.flush();
    assertEquals("MockFormatter_Head", this.errSubstituteStream.toString());
}
Also used : LogRecord(java.util.logging.LogRecord) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 37 with ConsoleHandler

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

the class LoggingHelper method loggerInit.

/**
   * Init java util logging
   *
   * @param level the Level of message to log
   * @param isRedirectStdOutErr whether we redirect std out&err
   * @param format the format to log
   */
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
    // Set the java util logging format
    setLoggingFormat(format);
    // Configure the root logger and its handlers so that all the
    // derived loggers will inherit the properties
    Logger rootLogger = Logger.getLogger("");
    for (Handler handler : rootLogger.getHandlers()) {
        handler.setLevel(level);
    }
    rootLogger.setLevel(level);
    if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
        // zookeeper logging scares me. if people want this, we can patch to config-drive this
        Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
    }
    if (isRedirectStdOutErr) {
        // System.err to Logger, it results in an infinite loop.
        for (Handler handler : rootLogger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                rootLogger.removeHandler(handler);
            }
        }
        // now rebind stdout/stderr to logger
        Logger logger;
        LoggingOutputStream los;
        logger = Logger.getLogger("stdout");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT);
        System.setOut(new PrintStream(los, true));
        logger = Logger.getLogger("stderr");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
        System.setErr(new PrintStream(los, true));
    }
}
Also used : PrintStream(java.io.PrintStream) FileHandler(java.util.logging.FileHandler) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 38 with ConsoleHandler

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

the class RootLogConfigTest method setUp.

@Before
public void setUp() {
    // Intercept stderr (this must be done first).
    fakeErrorLog = new ByteArrayOutputStream();
    errPrintStream = new PrintStream(fakeErrorLog);
    System.setErr(errPrintStream);
    // Create other members
    consoleHandler = new ConsoleHandler();
    fakeFileLog = new FakeHandler();
    // Emulate default setup (just a console handler), but avoiding the use
    // of the global root logger so not to get a flaky test due to background threads.
    fakeRootLogger = Logger.getLogger("FakeRoot-" + UUID.randomUUID().toString());
    fakeRootLogger.setUseParentHandlers(false);
    for (Handler h : fakeRootLogger.getHandlers()) {
        fakeRootLogger.removeHandler(h);
    }
    fakeRootLogger.addHandler(consoleHandler);
    testLogger = Logger.getLogger(RootLogConfigTest.class.getName());
    testLogger.setUseParentHandlers(true);
    testLogger.setParent(fakeRootLogger);
    setFakeRootForLogger(ClassA.logger);
    setFakeRootForLogger(ClassB.logger);
    resetLogs();
}
Also used : PrintStream(java.io.PrintStream) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConsoleHandler(java.util.logging.ConsoleHandler) Before(org.junit.Before)

Example 39 with ConsoleHandler

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

the class EndpointService 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 40 with ConsoleHandler

use of java.util.logging.ConsoleHandler 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)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)54 Handler (java.util.logging.Handler)23 Logger (java.util.logging.Logger)17 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)7 FileHandler (java.util.logging.FileHandler)6 File (java.io.File)5 PrintStream (java.io.PrintStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 Formatter (java.util.logging.Formatter)2 Level (java.util.logging.Level)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 ClassFileLoader (com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoader)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1