Search in sources :

Example 11 with ErrorManager

use of java.util.logging.ErrorManager in project tomee by apache.

the class FileHandler method configure.

/**
     * Configure from <code>LogManager</code> properties.
     */
private void configure() {
    final Timestamp ts = new Timestamp(System.currentTimeMillis());
    final String tsString = ts.toString().substring(0, 19);
    date = tsString.substring(0, 10);
    //allow classes to override
    final String className = this.getClass().getName();
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    // Retrieve configuration of logging file name
    rotatable = Boolean.parseBoolean(getProperty(className + ".rotatable", "true"));
    if (directory == null) {
        directory = getProperty(className + ".directory", "logs");
    }
    if (prefix == null) {
        prefix = getProperty(className + ".prefix", "juli.");
    }
    if (suffix == null) {
        suffix = getProperty(className + ".suffix", ".log");
    }
    final String sBufferSize = getProperty(className + ".bufferSize", String.valueOf(bufferSize));
    try {
        bufferSize = Integer.parseInt(sBufferSize);
    } catch (final NumberFormatException ignore) {
    //no op
    }
    // Get encoding for the logging file
    final String encoding = getProperty(className + ".encoding", null);
    if (encoding != null && encoding.length() > 0) {
        try {
            setEncoding(encoding);
        } catch (final UnsupportedEncodingException ex) {
        // Ignore
        }
    }
    // Get logging level for the handler
    setLevel(Level.parse(getProperty(className + ".level", String.valueOf(Level.ALL))));
    // Get filter configuration
    final String filterName = getProperty(className + ".filter", null);
    if (filterName != null) {
        try {
            setFilter((Filter) cl.loadClass(filterName).newInstance());
        } catch (final Exception e) {
        // Ignore
        }
    }
    // Set formatter
    final String formatterName = getProperty(className + ".formatter", null);
    if (formatterName != null) {
        try {
            setFormatter((Formatter) cl.loadClass(formatterName).newInstance());
        } catch (final Exception e) {
            // Ignore and fallback to defaults
            setFormatter(new SimpleFormatter());
        }
    } else {
        setFormatter(new SimpleFormatter());
    }
    // Set error manager
    setErrorManager(new ErrorManager());
}
Also used : ErrorManager(java.util.logging.ErrorManager) SimpleFormatter(java.util.logging.SimpleFormatter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Timestamp(java.sql.Timestamp) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ErrorManager (java.util.logging.ErrorManager)11 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Handler (java.util.logging.Handler)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Timestamp (java.sql.Timestamp)2 Formatter (java.util.logging.Formatter)2 LogRecord (java.util.logging.LogRecord)2 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 PrintStream (java.io.PrintStream)1 Properties (java.util.Properties)1 Filter (java.util.logging.Filter)1 SimpleFormatter (java.util.logging.SimpleFormatter)1