All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.izforge.izpack.util.LogHandler Maven / Gradle / Ivy

There is a newer version: 5.2.3
Show newest version
package com.izforge.izpack.util;

import java.util.logging.*;

/**
 * A variant of the default Java logging ConsoleHandler, not being so messy
 *
 * @author rkrell
 */
public class LogHandler extends StreamHandler
{
    /**
     * Create a LogHandler for System.err.
     * 

* The LogHandler is configured based on LogManager properties (or their * default values). * */ public LogHandler() { configure(); setOutputStream(System.err); } private void configure() { LogManager manager = LogManager.getLogManager(); String cname = getClass().getName(); // Try loading configured formatter first String formatterName = manager.getProperty(cname + ".formatter"); Formatter formatter = null; try { if (formatterName != null) { Class formatterClass = (Class) ClassLoader.getSystemClassLoader().loadClass(formatterName); formatter = (Formatter) formatterClass.newInstance(); } } catch (Exception ex) { // We got one of a variety of exceptions in creating the // class or creating an instance. // Drop through. } // Load IzPack default formatter, if nothing was configured if (formatter == null) { formatter = new LogFormatter(); } setFormatter(formatter); if (Debug.isDEBUG()) { setLevel(Level.FINE); } else { setLevel(Level.INFO); } } /** * Publish a LogRecord. *

* The logging request was made initially to a Logger object, which initialized the * LogRecord and forwarded it here. *

* * @param record description of the log event. A null record is silently ignored and is not * published */ @Override public void publish(LogRecord record) { super.publish(record); flush(); } /** * Override LogHandler.close to do a flush but not to close the output stream. That * is, we do not close System.err. */ @Override public void close() { flush(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy