Example usage for java.util.logging Handler setLevel

List of usage examples for java.util.logging Handler setLevel

Introduction

In this page you can find the example usage for java.util.logging Handler setLevel.

Prototype

public synchronized void setLevel(Level newLevel) throws SecurityException 

Source Link

Document

Set the log level specifying which message levels will be logged by this Handler .

Usage

From source file:jshm.logging.Log.java

public static void reloadConfig() throws Exception {
    // all logging
    Handler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(DEBUG ? Level.ALL : Level.WARNING);
    consoleHandler.setFormatter(new OneLineFormatter());

    Logger cur = Logger.getLogger("");
    removeHandlers(cur);/* ww  w.j  ava  2 s .  c  om*/

    cur.addHandler(consoleHandler);

    // jshm logging
    Formatter fileFormatter = new FileFormatter();
    Handler jshmHandler = new FileHandler("data/logs/JSHManager.txt");
    jshmHandler.setLevel(Level.ALL);
    jshmHandler.setFormatter(fileFormatter);

    cur = Logger.getLogger("jshm");
    cur.addHandler(jshmHandler);
    cur.setLevel(DEBUG ? Level.ALL : Level.INFO);

    // hibernate logging
    Handler hibernateHandler = new FileHandler("data/logs/Hibernate.txt");
    hibernateHandler.setLevel(Level.ALL);
    hibernateHandler.setFormatter(fileFormatter);

    cur = Logger.getLogger("org.hibernate");
    removeHandlers(cur);

    cur.addHandler(hibernateHandler);
    cur.setLevel(DEBUG ? Level.INFO : Level.WARNING);

    // HttpClient logging
    Handler httpClientHandler = new FileHandler("data/logs/HttpClient.txt");
    httpClientHandler.setLevel(Level.ALL);
    httpClientHandler.setFormatter(fileFormatter);

    //      cur = Logger.getLogger("httpclient.wire");
    cur = Logger.getLogger("httpclient.wire.header");
    removeHandlers(cur);

    cur.addHandler(httpClientHandler);
    cur.setLevel(DEBUG ? Level.ALL : Level.INFO);

    cur = Logger.getLogger("org.apache.commons.httpclient");
    removeHandlers(cur);

    cur.addHandler(httpClientHandler);
    cur.setLevel(DEBUG ? Level.FINER : Level.INFO);

    // HtmlParser logging
    Handler htmlParserHandler = new FileHandler("data/logs/HtmlParser.txt");
    htmlParserHandler.setLevel(Level.ALL);
    htmlParserHandler.setFormatter(fileFormatter);

    cur = Logger.getLogger("org.htmlparser");
    removeHandlers(cur);

    cur.addHandler(htmlParserHandler);
    cur.setLevel(DEBUG ? Level.ALL : Level.INFO);

    // SwingX logging
    Handler swingxHandler = new FileHandler("data/logs/SwingX.txt");
    swingxHandler.setLevel(Level.ALL);
    swingxHandler.setFormatter(fileFormatter);

    cur = Logger.getLogger("org.jdesktop.swingx");
    removeHandlers(cur);

    cur.addHandler(swingxHandler);
    cur.setLevel(DEBUG ? Level.ALL : Level.INFO);
}

From source file:org.freaknet.gtrends.client.GoogleTrendsClientFactory.java

private static void setLogLevel(CmdLineParser cmdLine) throws SecurityException, IllegalArgumentException {
    final Level level;
    if (cmdLine.getLogLevel() != null) {
        level = Level.parse(cmdLine.getLogLevel());
    } else {/*from   w  w  w. j a  v  a  2s. c o m*/
        level = Level.parse(DEFAULT_LOGGING_LEVEL);
    }
    Logger log = LogManager.getLogManager().getLogger("");

    for (Handler h : log.getHandlers()) {
        log.removeHandler(h);
    }
    Handler handler = new ConsoleHandler();
    handler.setFormatter(new LogFormatter());
    handler.setLevel(level);
    log.setUseParentHandlers(false);

    Logger defaultLog = Logger.getLogger(GoogleConfigurator.getLoggerPrefix());
    defaultLog.addHandler(handler);
    defaultLog.setLevel(level);
    defaultLog.setFilter(new Filter() {
        @Override
        public boolean isLoggable(LogRecord record) {
            if (record.getSourceClassName().startsWith(GoogleConfigurator.getLoggerPrefix())) {
                return (record.getLevel().intValue() >= level.intValue());
            }
            return false;
        }
    });
}

From source file:jenkins.model.RunIdMigratorTest.java

@BeforeClass
public static void logging() {
    RunIdMigrator.LOGGER.setLevel(Level.ALL);
    Handler handler = new ConsoleHandler();
    handler.setLevel(Level.ALL);
    RunIdMigrator.LOGGER.addHandler(handler);
}

From source file:org.jenkinsci.plugins.workflow.cps.SnippetizerTest.java

@BeforeClass
public static void logging() {
    logger.setLevel(Level.ALL);/*  ww  w.  j  a va 2 s  . co m*/
    Handler handler = new ConsoleHandler();
    handler.setLevel(Level.ALL);
    logger.addHandler(handler);
}

From source file:com.twitter.heron.common.utils.logging.LoggingHelper.java

/**
 * Init java util logging/*from w ww  . ja  v  a  2s.com*/
 *
 * @param level the Level of message to log
 * @param isRedirectStdOutErr whether we redirect std out&err
 * @param format the format to log
 */
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
    // Set the java util logging format
    setLoggingFormat(format);

    // Configure the root logger and its handlers so that all the
    // derived loggers will inherit the properties
    Logger rootLogger = Logger.getLogger("");
    for (Handler handler : rootLogger.getHandlers()) {
        handler.setLevel(level);
    }

    rootLogger.setLevel(level);

    if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
        // zookeeper logging scares me. if people want this, we can patch to config-drive this
        Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
    }

    // setting logging for http client to be error level
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "ERROR");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "ERROR");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "ERROR");

    if (isRedirectStdOutErr) {

        // Remove ConsoleHandler if present, to avoid StackOverflowError.
        // ConsoleHandler writes to System.err and since we are redirecting
        // System.err to Logger, it results in an infinite loop.
        for (Handler handler : rootLogger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                rootLogger.removeHandler(handler);
            }
        }

        // now rebind stdout/stderr to logger
        Logger logger;
        LoggingOutputStream los;

        logger = Logger.getLogger("stdout");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT);
        System.setOut(new PrintStream(los, true));

        logger = Logger.getLogger("stderr");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
        System.setErr(new PrintStream(los, true));
    }
}

From source file:de.fosd.jdime.config.JDimeConfig.java

/**
 * Set the logging level. The levels in descending order are:<br>
 *
 * <ul>/*from w  ww  .  j  a v  a2  s  .c  o  m*/
 *  <li>ALL</li>
 *  <li>SEVERE (highest value)</li>
 *  <li>WARNING</li>
 *  <li>INFO</li>
 *  <li>CONFIG</li>
 *  <li>FINE</li>
 *  <li>FINER</li>
 *  <li>FINEST (lowest value)</li>
 *  <li>OFF</li>
 * </ul>
 *
 * @param logLevel
 *             one of the valid log levels according to {@link Level#parse(String)}
 */
public static void setLogLevel(String logLevel) {
    Level level;

    try {
        level = Level.parse(logLevel.toUpperCase());
    } catch (IllegalArgumentException e) {
        LOG.warning(
                () -> "Invalid log level %s. Must be one of OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST or ALL.");
        return;
    }

    Logger root = Logger.getLogger(Main.class.getPackage().getName());
    root.setLevel(level);

    for (Handler handler : root.getHandlers()) {
        handler.setLevel(level);
    }
}

From source file:com.tri_voltage.md.io.YoutubeVideoParser.java

private static void explicitlySetAllLogging(Level myLevel, Level globalLevel) {
    rootlog.setLevel(Level.ALL);//from w  w w.  j ava2s .  co m
    for (Handler handler : rootlog.getHandlers()) {
        handler.setLevel(Level.ALL);
    }
    log.setLevel(myLevel);
    rootlog.setLevel(globalLevel);
}

From source file:test.db_memory.QualitativeTest.java

@Test(dataProvider = "quantitative", groups = "")
public static void testBasic(TestDescription test)
        throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    Logger.getRootLogger().setLevel(org.apache.log4j.Level.ALL);
    java.util.logging.Logger.getGlobal().setLevel(Level.FINEST);
    java.util.logging.Logger.getGlobal().setUseParentHandlers(false);
    Handler newHandler = new ConsoleHandler();
    newHandler.setLevel(Level.FINEST);
    java.util.logging.Logger.getGlobal().addHandler(newHandler);

    CoreseTimer timerMemory = null;//from   w  w w .  ja  v a2  s.co m
    CoreseTimer timerDb = null;
    try {
        setCacheForDb(test);
        System.gc();
        timerDb = CoreseTimer.build(test).setMode(CoreseTimer.Profile.DB).init().run();
        System.gc();
        timerMemory = CoreseTimer.build(test).setMode(CoreseTimer.Profile.MEMORY).init().run();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    System.out.println("running test: " + test.getId());
    boolean result;
    try {
        result = compareResults(timerDb.getMapping(), timerMemory.getMapping());
    } catch (Exception ex) {
        ex.printStackTrace();
        result = false;
    }
    test.setResultsEqual(result);
    timerDb.writeResults();
    timerDb.writeStatistics();
    timerMemory.writeResults();
    timerMemory.writeStatistics();
    //      writeResult(test, timerDb, timerMemory);
    assertTrue(result, test.getId());
}

From source file:org.noroomattheinn.utils.Utils.java

public static void setupLogger(File where, String basename, Logger logger, Level level) {
    rotateLogs(where, basename, 3);/*from   w  w  w  .j a  v a  2  s.  com*/

    FileHandler fileHandler;
    try {
        logger.setLevel(level);
        fileHandler = new FileHandler((new File(where, basename + "-00.log")).getAbsolutePath());
        fileHandler.setFormatter(new SimpleFormatter());
        fileHandler.setLevel(level);
        logger.addHandler(fileHandler);

        for (Handler handler : Logger.getLogger("").getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                handler.setLevel(level);
            }
        }
    } catch (IOException | SecurityException ex) {
        logger.severe("Unable to establish log file: " + ex);
    }
}

From source file:org.openqa.selenium.server.log.LoggingManager.java

protected static void restoreOriginalHandlersFormattersAndLevels(Logger logger) {
    for (Handler handler : logger.getHandlers()) {
        logger.removeHandler(handler);//from  ww  w  . j  av a2s  . c  o  m
    }
    for (Handler handler : originalHandlers) {
        logger.addHandler(handler);
        // jbevan: java.util.logging.RestishHandler.setFormatter(null) throws an NPE
        if (originalFormatters.get(handler) != null) {
            handler.setFormatter(originalFormatters.get(handler));
        }
        handler.setLevel(originalLogLevels.get(handler));
    }
}