SupportWriter space ↗
← Back to the journal
Logging

How do I use logger ConsoleHandler?

In this example you’ll see how to add ConsoleHandler to the Logger instance. It is simple, just create an instance of ConsoleHandler and add it to the Logger using the Logger.addHandler() method. package org.kodejava.util.logging; import java.util.logging.Logger; import java.util.logging.ConsoleHandler; import java.util.logging.Level; public class LogConsoleHandler { public static void main(String[] args) { // Obtains Logger instance Logger […]

DWayan · 23 Feb 2009 · 1 min read

Article by Wayan · Source: Kode Java ↗

In this example you’ll see how to add ConsoleHandler to the Logger instance. It is simple, just create an instance of ConsoleHandler and add it to the Logger using the Logger.addHandler() method.

package org.kodejava.util.logging;

import java.util.logging.Logger;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;

public class LogConsoleHandler {
    public static void main(String[] args) {
        // Obtains Logger instance
        Logger logger = Logger.getLogger(LogConsoleHandler.class.getName());

        // Add ConsoleHandler to Logger.
        ConsoleHandler consoleHandler = new ConsoleHandler();
        logger.addHandler(consoleHandler);

        if (logger.isLoggable(Level.INFO)) {
            logger.info("This is information message for testing ConsoleHandler");
        }
    }
}
← Explore more notes