Example usage for java.util.logging Logger getHandlers

List of usage examples for java.util.logging Logger getHandlers

Introduction

In this page you can find the example usage for java.util.logging Logger getHandlers.

Prototype

public Handler[] getHandlers() 

Source Link

Document

Get the Handlers associated with this logger.

Usage

From source file:ste.xtest.logging.BugFreeLoggingByteArrayOutputStream.java

private Logger getLog() {
    Logger log = Logger.getLogger("ste.xtest.logging");

    for (Handler h : log.getHandlers()) {
        log.removeHandler(h);/* w  w  w . ja va 2  s.  c  o  m*/
    }

    log.addHandler(new ListLogHandler());

    return log;
}

From source file:org.kalypso.model.hydrology.internal.test.OptimizeTest.java

private void disconnectLogger(final Logger logger) {
    final Handler[] handlers = logger.getHandlers();
    for (final Handler handler : handlers) {
        handler.close();/*from  www .  ja va2s  .  c  o m*/
        logger.removeHandler(handler);
    }
}

From source file:org.springframework.boot.logging.log4j.Log4JLoggingSystemTests.java

private boolean bridgeHandlerInstalled() {
    java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
        if (handler instanceof SLF4JBridgeHandler) {
            return true;
        }/*from   ww w.j a  va 2  s  .  c om*/
    }
    return false;
}

From source file:edu.usu.sdl.openstorefront.web.action.admin.LoggingAction.java

@DefaultHandler
public Resolution viewLoggers() {
    StringBuilder results = new StringBuilder();

    List<String> allLoggers = LogManager.getLoggingMXBean().getLoggerNames();
    Collections.sort(allLoggers);
    results.append(// w  w w  . j  a  v  a 2  s .  c o m
            "<table border='1'><tr style='background-color: lightgrey; '><th >Logger</th><th>Level</th><th>Handlers</th>");
    for (String name : allLoggers) {
        results.append("<tr>");
        Level levelLocal = LogManager.getLogManager().getLogger(name).getLevel();
        String levelName = "";
        if (levelLocal != null) {
            levelName = levelLocal.getName();
        }
        results.append("<td><b>").append(name).append("</b></td><td> ").append(levelName).append("</td>");

        results.append("<td>");
        Logger localLogger = LogManager.getLogManager().getLogger(name);
        for (Handler handlerLocal : localLogger.getHandlers()) {
            results.append(handlerLocal.getClass().getName()).append(" = ")
                    .append(handlerLocal.getLevel().getName()).append("<br>");
        }
        results.append("</td>");

        results.append("</tr>");
    }
    results.append("</table>");
    return new StreamingResolution("text/html", results.toString());
}

From source file:org.javaan.JavaanCli.java

private void setLoggerLevel(Level level) {
    Logger logger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = logger.getHandlers();
    for (Handler handler : handlers) {
        handler.setLevel(level);/*w  ww.j a v a2 s.  com*/
    }
    logger.setLevel(level);
}

From source file:com.google.appengine.tck.logservice.LoggingTestBase.java

protected void flush(Logger log) {
    ApiProxy.flushLogs();//w  ww .jav  a 2 s  .c o  m
    for (Handler handler : log.getHandlers()) {
        handler.flush();
    }
}

From source file:org.kalypso.model.hydrology.internal.test.OptimizeTest.java

private Logger createLogger(final File logFile) throws SecurityException, IOException {
    final Logger logger = Logger.getAnonymousLogger();
    final Handler[] handlers = logger.getHandlers();
    for (final Handler handler : handlers)
        logger.removeHandler(handler);/*from   ww  w.j a v  a 2 s . c  o  m*/

    final FileHandler fileHandler = new FileHandler(logFile.getAbsolutePath());
    logger.addHandler(fileHandler);

    return logger;
}

From source file:edu.usu.sdl.openstorefront.web.action.admin.LoggingAction.java

@HandlesEvent("UpdateHandlerLevel")
public Resolution updateHandlerLevel() {
    Logger localLogger = LogManager.getLogManager().getLogger(logger);
    if (localLogger != null) {

        for (Handler handlerLocal : localLogger.getHandlers()) {
            if (handlerLocal.getClass().getName().equals(handler)) {
                if (StringUtils.isNotBlank(level)) {
                    handlerLocal.setLevel(Level.parse(level));
                } else {
                    handlerLocal.setLevel(null);
                }/*w ww .j a  va 2s  .  c  o m*/
            }
        }
        log.log(Level.INFO, SecurityUtil.adminAuditLogMessage(getContext().getRequest()));
    } else {
        throw new OpenStorefrontRuntimeException("Unable to find logger", "Check name");
    }

    return viewLoggers();
}

From source file:org.apache.hcatalog.templeton.Main.java

private void initLogger() {
    java.util.logging.Logger rootLogger = java.util.logging.LogManager.getLogManager().getLogger("");
    for (java.util.logging.Handler h : rootLogger.getHandlers())
        rootLogger.removeHandler(h);/* w w  w  . j a v a 2 s. c o  m*/

    SLF4JBridgeHandler.install();
}

From source file:org.openqa.selenium.server.SingleEntryAsyncQueueUnitTest.java

private void configureLogging() throws Exception {
    LoggingManager.configureLogging(new LoggingOptions(), true);
    Logger logger = Logger.getLogger("");
    for (Handler handler : logger.getHandlers()) {
        if (handler instanceof StdOutHandler) {
            handler.setFormatter(new TerseFormatter(true));
            break;
        }/*from   ww  w  . j a  va  2  s.c o  m*/
    }
}