Search in sources :

Example 51 with Handler

use of java.util.logging.Handler in project grpc-java by grpc.

the class ContextTest method detachingNonCurrentLogsSevereMessage.

@Test
public void detachingNonCurrentLogsSevereMessage() {
    final AtomicReference<LogRecord> logRef = new AtomicReference<LogRecord>();
    Handler handler = new Handler() {

        @Override
        public void publish(LogRecord record) {
            logRef.set(record);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };
    Logger logger = Logger.getLogger(Context.storage().getClass().getName());
    try {
        logger.addHandler(handler);
        Context initial = Context.current();
        Context base = initial.withValue(PET, "dog");
        // Base is not attached
        base.detach(initial);
        assertSame(initial, Context.current());
        assertNotNull(logRef.get());
        assertEquals(Level.SEVERE, logRef.get().getLevel());
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Handler(java.util.logging.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 52 with Handler

use of java.util.logging.Handler in project jmonkeyengine by jMonkeyEngine.

the class TestCanvas method main.

public static void main(String[] args) {
    JmeFormatter formatter = new JmeFormatter();
    Handler consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(formatter);
    Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
    Logger.getLogger("").addHandler(consoleHandler);
    createCanvas(appClass);
    try {
        Thread.sleep(500);
    } catch (InterruptedException ex) {
    }
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            JPopupMenu.setDefaultLightWeightPopupEnabled(false);
            createFrame();
            currentPanel.add(canvas, BorderLayout.CENTER);
            frame.pack();
            startApp();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
}
Also used : JmeFormatter(com.jme3.util.JmeFormatter) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 53 with Handler

use of java.util.logging.Handler in project jmonkeyengine by jMonkeyEngine.

the class AndroidHarness method initializeLogHandler.

/**
     * Removes the standard Android log handler due to an issue with not logging
     * entries lower than INFO level and adds a handler that produces
     * JME formatted log messages.
     */
protected void initializeLogHandler() {
    Logger log = LogManager.getLogManager().getLogger("");
    for (Handler handler : log.getHandlers()) {
        if (log.getLevel() != null && log.getLevel().intValue() <= Level.FINE.intValue()) {
            Log.v("AndroidHarness", "Removing Handler class: " + handler.getClass().getName());
        }
        log.removeHandler(handler);
    }
    Handler handler = new AndroidLogHandler();
    log.addHandler(handler);
    handler.setLevel(Level.ALL);
}
Also used : AndroidLogHandler(com.jme3.util.AndroidLogHandler) AndroidLogHandler(com.jme3.util.AndroidLogHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Example 54 with Handler

use of java.util.logging.Handler in project jmonkeyengine by jMonkeyEngine.

the class AndroidHarnessFragment method initializeLogHandler.

/**
     * Removes the standard Android log handler due to an issue with not logging
     * entries lower than INFO level and adds a handler that produces
     * JME formatted log messages.
     */
protected void initializeLogHandler() {
    Logger log = LogManager.getLogManager().getLogger("");
    for (Handler handler : log.getHandlers()) {
        if (log.getLevel() != null && log.getLevel().intValue() <= Level.FINE.intValue()) {
            Log.v("AndroidHarness", "Removing Handler class: " + handler.getClass().getName());
        }
        log.removeHandler(handler);
    }
    Handler handler = new AndroidLogHandler();
    log.addHandler(handler);
    handler.setLevel(Level.ALL);
}
Also used : AndroidLogHandler(com.jme3.util.AndroidLogHandler) AndroidLogHandler(com.jme3.util.AndroidLogHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Example 55 with Handler

use of java.util.logging.Handler in project hudson-2.x by hudson.

the class WeakLogHandler method setFormatter.

@Override
public void setFormatter(Formatter newFormatter) throws SecurityException {
    super.setFormatter(newFormatter);
    Handler t = resolve();
    if (t != null)
        t.setFormatter(newFormatter);
}
Also used : Handler(java.util.logging.Handler)

Aggregations

Handler (java.util.logging.Handler)108 Logger (java.util.logging.Logger)35 ConsoleHandler (java.util.logging.ConsoleHandler)22 LogRecord (java.util.logging.LogRecord)16 Test (org.junit.Test)15 FileHandler (java.util.logging.FileHandler)13 IOException (java.io.IOException)9 File (java.io.File)8 Level (java.util.logging.Level)7 SimpleFormatter (java.util.logging.SimpleFormatter)7 Formatter (java.util.logging.Formatter)6 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)4 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2 ConsoleLogFormatter (alma.acs.logging.formatters.ConsoleLogFormatter)2 MonitoredResource (com.google.cloud.MonitoredResource)2