Search in sources :

Example 71 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project mssql-jdbc by Microsoft.

the class AbstractTest method invokeLogging.

/**
 * Invoke logging.
 */
public static void invokeLogging() {
    Handler handler = null;
    String enableLogging = getConfiguredProperty("mssql_jdbc_logging", "false");
    // If logging is not enable then return.
    if (!"true".equalsIgnoreCase(enableLogging)) {
        return;
    }
    String loggingHandler = getConfiguredProperty("mssql_jdbc_logging_handler", "not_configured");
    try {
        // handler = new FileHandler("Driver.log");
        if ("console".equalsIgnoreCase(loggingHandler)) {
            handler = new ConsoleHandler();
        } else if ("file".equalsIgnoreCase(loggingHandler)) {
            handler = new FileHandler("Driver.log");
            System.out.println("Look for Driver.log file in your classpath for detail logs");
        }
        if (handler != null) {
            handler.setFormatter(new SimpleFormatter());
            handler.setLevel(Level.FINEST);
            Logger.getLogger("").addHandler(handler);
        }
        // By default, Loggers also send their output to their parent logger.  
        // Typically the root Logger is configured with a set of Handlers that essentially act as default handlers for all loggers. 
        Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc");
        logger.setLevel(Level.FINEST);
    } catch (Exception e) {
        System.err.println("Some how could not invoke logging: " + e.getMessage());
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) 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) FileHandler(java.util.logging.FileHandler)

Example 72 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project runwar by cfmlprojects.

the class LogRequest method init.

public void init(ServletConfig config) {
    this.logLevel = config.getInitParameter("logLevel");
    this.logFilePath = config.getInitParameter("logFilePath");
    boolean append = true;
    FileHandler handler;
    try {
        handler = new FileHandler(this.logFilePath, append);
        handler.setFormatter(new SimpleFormatter());
        log.addHandler(handler);
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
// Add to the desired logger
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) IOException(java.io.IOException) FileHandler(java.util.logging.FileHandler)

Example 73 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project openj9 by eclipse.

the class LibraryCollector method main.

// used for testing purposes
public static void main(String[] args) {
    LibraryCollector collector = new LibraryCollector();
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.FINEST);
    Formatter formatter = new SimpleFormatter();
    handler.setFormatter(formatter);
    Logger log = Logger.getLogger(PUBLIC_LOGGER_NAME);
    log.addHandler(handler);
    log.setLevel(Level.FINEST);
    // assumes args[0] is the path to the core file, args[1] is the type of collection
    CollectorResult result = collector.collectLibrariesFor(args[0], args[1]);
    System.out.println("Collection completed with result : " + result.name());
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) Formatter(java.util.logging.Formatter) SimpleFormatter(java.util.logging.SimpleFormatter) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 74 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project openj9 by eclipse.

the class Session method enableConsoleLogging.

/**
 * Enables console logger for the supplied logger. Typically used to surface
 * log commands generated by internal components
 *
 * @param log the logger to enable
 */
private void enableConsoleLogging(Logger log) {
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.FINE);
    Formatter formatter = new SimpleFormatter();
    handler.setFormatter(formatter);
    log.addHandler(handler);
    log.setLevel(Level.FINE);
    if (isVerboseEnabled) {
        out.println("Console logging is now enabled for " + log.getName());
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) Formatter(java.util.logging.Formatter) SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 75 with SimpleFormatter

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

SimpleFormatter (java.util.logging.SimpleFormatter)100 FileHandler (java.util.logging.FileHandler)59 Logger (java.util.logging.Logger)36 File (java.io.File)28 Handler (java.util.logging.Handler)23 IOException (java.io.IOException)17 StreamHandler (java.util.logging.StreamHandler)16 Properties (java.util.Properties)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 LogRecord (java.util.logging.LogRecord)13 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)13 Config (edu.neu.ccs.pyramid.configuration.Config)11 ConsoleHandler (java.util.logging.ConsoleHandler)10 Formatter (java.util.logging.Formatter)9 Test (org.junit.Test)7 MockResponse (com.google.mockwebserver.MockResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 Pair (edu.neu.ccs.pyramid.util.Pair)3