Example usage for java.util.logging Handler getLevel

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

Introduction

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

Prototype

public Level getLevel() 

Source Link

Document

Get the log level specifying which messages will be logged by this Handler .

Usage

From source file:com.twitter.common.net.http.handlers.LogConfig.java

private void maybeAdjustHandlerLevels(Logger logger, Level newLevel) {
    do {//from  www  .j  a  v a 2  s. com
        for (Handler handler : logger.getHandlers()) {
            Level handlerLevel = handler.getLevel();
            if (newLevel.intValue() < handlerLevel.intValue()) {
                handler.setLevel(newLevel);
            }
        }
    } while (logger.getUseParentHandlers() && (logger = logger.getParent()) != null);
}

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(/*from  w ww  . j  av 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:com.googlecode.fightinglayoutbugs.FightingLayoutBugs.java

private void enableDebugOutputToConsole(Logger logger) {
    do {/*from w w  w.ja  v a  2  s  . c  o m*/
        for (final Handler handler : logger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                final Level originalConsoleLogLevel = handler.getLevel();
                handler.setLevel(Level.FINE);
                _runAfterAnalysis.add(new Runnable() {
                    @Override
                    public void run() {
                        handler.setLevel(originalConsoleLogLevel);
                    }
                });
            }
        }
    } while (logger.getUseParentHandlers() && (logger = logger.getParent()) != null);
}

From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java

@GET
@RequireAdmin/*ww w  .  j  av  a2 s.c o m*/
@APIDescription("Gets Loggers in the system")
@Produces({ MediaType.APPLICATION_JSON })
@DataType(LoggerView.class)
@Path("/loggers")
public List<LoggerView> getLoggers() {
    List<LoggerView> loggers = new ArrayList<>();

    List<String> allLoggers = LogManager.getLoggingMXBean().getLoggerNames();
    Collections.sort(allLoggers);

    for (String name : allLoggers) {
        LoggerView loggerView = new LoggerView();
        loggerView.setName(name);

        Level levelLocal = LogManager.getLogManager().getLogger(name).getLevel();
        String levelName = "";
        if (levelLocal != null) {
            levelName = levelLocal.getName();
        }
        loggerView.setLevel(levelName);

        Logger localLogger = LogManager.getLogManager().getLogger(name);
        for (Handler handlerLocal : localLogger.getHandlers()) {
            loggerView.getHandlers()
                    .add(handlerLocal.getClass().getName() + " = " + handlerLocal.getLevel().getName());
        }
        loggers.add(loggerView);
    }

    return loggers;
}

From source file:org.callimachusproject.repository.CalliRepository.java

private void setHandlerLevel(Logger logger, Level level) {
    if (logger.getParent() != null) {
        setHandlerLevel(logger.getParent(), level);
    }/*from   w  w  w  .  j a va 2  s. com*/
    Handler[] handlers = logger.getHandlers();
    if (handlers != null) {
        for (Handler handler : handlers) {
            if (handler.getLevel().intValue() > level.intValue()) {
                handler.setLevel(level);
            }
        }
    }
}

From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java

@PUT
@RequireAdmin/*from w  ww .  j a  v  a  2  s  . com*/
@APIDescription("Sets logger level")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.WILDCARD })
@DataType(LoggerView.class)
@Path("/logger/{loggername}/level")
public Response updateApplicationProperty(@PathParam("loggername") @RequiredParam String loggername,
        String level) {
    Response response = Response.status(Response.Status.NOT_FOUND).build();
    Logger logger = LogManager.getLogManager().getLogger(loggername);
    if (logger != null) {
        List<String> levels = loadLevels();
        boolean saved = false;
        if (StringUtils.isBlank(level)) {
            logger.setLevel(null);
            saved = true;
        } else {
            if (levels.contains(level)) {
                logger.setLevel(Level.parse(level));
                saved = true;
            } else {
                RestErrorModel restErrorModel = new RestErrorModel();
                restErrorModel.getErrors().put("level", "Log level is not valid. Check level value passed in.");
                response = Response.ok(restErrorModel).build();
            }
        }
        if (saved) {
            LoggerView loggerView = new LoggerView();
            loggerView.setName(loggername);
            loggerView.setLevel(level);
            for (Handler handlerLocal : logger.getHandlers()) {
                loggerView.getHandlers()
                        .add(handlerLocal.getClass().getName() + " = " + handlerLocal.getLevel().getName());
            }
            response = Response.ok(loggerView).build();
        }
    }
    return response;
}

From source file:de.ailis.jasdoc.Main.java

/**
 * Initializes logging.//from  www  .  j  a  v a2  s .  c o  m
 */
private void initLogging() {
    final Logger logger = Logger.getLogger("de.ailis.jasdoc");
    logger.setUseParentHandlers(false);
    final Handler handler = new LogHandler();
    handler.setFilter(null);
    handler.setFormatter(new LogFormatter(this.debug));
    if (this.debug)
        handler.setLevel(Level.ALL);
    else if (this.quiet)
        handler.setLevel(Level.WARNING);
    else
        handler.setLevel(Level.INFO);
    logger.setFilter(null);
    logger.addHandler(handler);
    Logger.getLogger("").setLevel(handler.getLevel());
}

From source file:MailHandlerDemo.java

/**
 * Gets a formatting string describing the given handler.
 *
 * @param prefix the output prefix.//from   www.j  a va  2  s. co m
 * @param err the error stream.
 * @param h the handler.
 * @return the formatted string.
 */
private static String toString(String prefix, PrintStream err, Handler h) {
    StringBuilder buf = new StringBuilder();
    buf.append(h.getClass().getName());
    try {
        if (h instanceof MailHandler) {
            MailHandler mh = (MailHandler) h;
            buf.append(", ").append(mh.getSubject());
        }
    } catch (SecurityException error) {
        err.print(prefix + ": ");
        error.printStackTrace(err);
    }

    try {
        buf.append(", ").append(h.getFormatter());
    } catch (SecurityException error) {
        err.print(prefix + ": ");
        error.printStackTrace(err);
    }

    try {
        if (h instanceof MailHandler) {
            MailHandler mh = (MailHandler) h;
            buf.append(", ").append(Arrays.toString(mh.getAttachmentFormatters()));
        }
    } catch (SecurityException error) {
        err.print(prefix + ": ");
        error.printStackTrace(err);
    }

    try {
        buf.append(", ").append(h.getLevel());
    } catch (SecurityException error) {
        err.print(prefix + ": ");
        error.printStackTrace(err);
    }

    try {
        buf.append(", ").append(h.getFilter());
    } catch (SecurityException error) {
        err.print(prefix + ": ");
        error.printStackTrace(err);
    }

    try {
        buf.append(", ").append(h.getErrorManager());
    } catch (SecurityException error) {
        err.print(prefix + ": ");
        error.printStackTrace(err);
    }

    buf.append(", ").append(toString(h.getClass().getClassLoader()));
    return buf.toString();
}

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

public static void overrideSimpleFormatterWithTerseOneForConsoleHandler(Logger logger, boolean debugMode) {
    for (Handler handler : logger.getHandlers()) {
        if (handler instanceof ConsoleHandler) {
            final Formatter formatter;

            formatter = handler.getFormatter();
            if (formatter instanceof SimpleFormatter) {
                final StdOutHandler stdOutHandler;
                final Level originalLevel;

                /*// www.ja v  a  2s  . c  o m
                 * DGF - Nobody likes the SimpleFormatter; surely they wanted our terse formatter instead.
                 */
                originalLevel = handler.getLevel();
                handler.setFormatter(new TerseFormatter(false));
                handler.setLevel(Level.WARNING);

                /*
                 * Furthermore, we all want DEBUG/INFO on stdout and WARN/ERROR on stderr
                 */
                stdOutHandler = new StdOutHandler();
                stdOutHandler.setFormatter(new TerseFormatter(false));
                stdOutHandler.setFilter(new MaxLevelFilter(Level.INFO));
                stdOutHandler.setLevel(originalLevel);
                logger.addHandler(stdOutHandler);
                if (debugMode) {
                    if (originalLevel.intValue() > Level.FINE.intValue()) {
                        stdOutHandler.setLevel(Level.FINE);
                    }
                }
            }
        }
    }
}

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

protected static void saveOriginalHandlersFormattersAndLevels(Logger logger) {
    originalHandlers = logger.getHandlers();
    originalFormatters = new HashMap<Handler, Formatter>();
    originalLogLevels = new HashMap<Handler, Level>();
    for (Handler handler : originalHandlers) {
        originalFormatters.put(handler, handler.getFormatter());
        originalLogLevels.put(handler, handler.getLevel());
    }//from   w w w .j  a v  a2 s.c o  m
}