Search in sources :

Example 41 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project CoreNLP by stanfordnlp.

the class MachineReading method setConsoleLevel.

public static void setConsoleLevel(Level level) {
    // get the top Logger:
    Logger topLogger = java.util.logging.Logger.getLogger("");
    // Handler for console (reuse it if it already exists)
    Handler consoleHandler = null;
    // see if there is already a console handler
    for (Handler handler : topLogger.getHandlers()) {
        if (handler instanceof ConsoleHandler) {
            // found the console handler
            consoleHandler = handler;
            break;
        }
    }
    if (consoleHandler == null) {
        // there was no console handler found, create a new one
        consoleHandler = new ConsoleHandler();
        topLogger.addHandler(consoleHandler);
    }
    // set the console handler level:
    consoleHandler.setLevel(level);
    consoleHandler.setFormatter(new SimpleFormatter());
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 42 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project okhttp by square.

the class Main method enableHttp2FrameLogging.

private static void enableHttp2FrameLogging() {
    frameLogger = Logger.getLogger(Http2.class.getName());
    frameLogger.setLevel(Level.FINE);
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.FINE);
    handler.setFormatter(new SimpleFormatter() {

        @Override
        public String format(LogRecord record) {
            return Util.format("%s%n", record.getMessage());
        }
    });
    frameLogger.addHandler(handler);
}
Also used : LogRecord(java.util.logging.LogRecord) SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 43 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project OpenGrok by OpenGrok.

the class LoggerUtil method initLogger.

public static String initLogger(String logpath, Level filelevel, Level consolelevel) throws IOException {
    if (logpath != null) {
        File jlp = new File(logpath);
        if (!jlp.exists() && !jlp.mkdirs()) {
            throw new RuntimeException("could not make logpath: " + jlp.getAbsolutePath());
        }
        if (!jlp.canWrite() && !Level.OFF.equals(filelevel)) {
            throw new IOException("logpath not writeable " + jlp.getAbsolutePath());
        }
    }
    Logger.getGlobal().setLevel(Level.OFF);
    getBaseLogger().setLevel(Level.ALL);
    StringBuilder logfile = new StringBuilder();
    logfile.append(logpath == null ? "%t" : logpath);
    logfile.append(File.separatorChar).append("opengrok%g.%u.log");
    try {
        FileHandler fh = new FileHandler(logfile.toString(), loggerIntProperty("java.util.logging.FileHandler.limit", DEFAULT_FILEHANDLER_LIMIT), loggerIntProperty("java.util.logging.FileHandler.count", DEFAULT_FILEHANDLER_COUNT));
        fh.setLevel(filelevel);
        String formatter = LogManager.getLogManager().getProperty("java.util.logging.FileHandler.formatter");
        try {
            fh.setFormatter((Formatter) Class.forName(formatter).newInstance());
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            fh.setFormatter(new FileLogFormatter());
        }
        getBaseLogger().addHandler(fh);
        loggerFile = logfile.toString();
        ConsoleHandler ch = new ConsoleHandler();
        ch.setLevel(consolelevel);
        ch.setFormatter(new ConsoleFormatter());
        getBaseLogger().addHandler(ch);
    } catch (IOException | SecurityException ex1) {
        LOGGER.log(Level.SEVERE, "Exception logging", ex1);
        throw new IOException("Exception setting up logging " + ex1);
    }
    return logpath;
}
Also used : FileLogFormatter(org.opensolaris.opengrok.logger.formatter.FileLogFormatter) IOException(java.io.IOException) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler) ConsoleFormatter(org.opensolaris.opengrok.logger.formatter.ConsoleFormatter) File(java.io.File)

Example 44 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project gfm_viewer by satyagraha.

the class LogManager method configChanged.

@EventSubscriber(eventClass = Config.Changed.class)
public void configChanged(Config.Changed configChanged) {
    Level level = debugging || config.useEclipseConsole() ? Level.FINE : Level.INFO;
    logger.setLevel(level);
    if (consoleHandler == null) {
        consoleHandler = new ConsoleHandler();
        consoleHandler.setFormatter(formatter);
        logger.addHandler(consoleHandler);
    }
    if (logConsoleHandler == null && config.useEclipseConsole()) {
        LogConsole.start(GFM_CONSOLE);
        logConsoleHandler = LogConsole.getInstance().createHandler(formatter);
        logger.addHandler(logConsoleHandler);
    }
    for (Handler handler : logger.getHandlers()) {
        handler.setLevel(level);
    }
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Level(java.util.logging.Level) ConsoleHandler(java.util.logging.ConsoleHandler) EventSubscriber(org.bushe.swing.event.annotation.EventSubscriber)

Example 45 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project ACS by ACS-Community.

the class TestLogger method getLogger.

/**
	 * Returns a simple JDK logger that's configured to use a <code>ConsoleHandler</code>.
	 * It will log messages to the console (syserr) and ignore log levels below <code>level</code>. 
	 * @param name  logger name
	 * @param level minimum level of messages to be not discarded
	 */
public static Logger getLogger(String name, Level level) {
    Logger logger = Logger.getLogger(name);
    logger.setLevel(level);
    logger.setUseParentHandlers(false);
    // in JUnit tests, the intended fresh logger may actually be recycled and already have the handler set.
    Handler logHandler = null;
    for (Handler handler : logger.getHandlers()) {
        if (handler instanceof ConsoleHandler) {
            logHandler = handler;
            break;
        }
    }
    if (logHandler == null) {
        logHandler = new ConsoleHandler();
        logger.addHandler(logHandler);
    }
    logHandler.setLevel(level);
    return logger;
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)54 Handler (java.util.logging.Handler)23 Logger (java.util.logging.Logger)17 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)7 FileHandler (java.util.logging.FileHandler)6 File (java.io.File)5 PrintStream (java.io.PrintStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 Formatter (java.util.logging.Formatter)2 Level (java.util.logging.Level)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 ClassFileLoader (com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoader)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1