Example usage for java.util.logging LoggingMXBean getLoggerLevel

List of usage examples for java.util.logging LoggingMXBean getLoggerLevel

Introduction

In this page you can find the example usage for java.util.logging LoggingMXBean getLoggerLevel.

Prototype

public String getLoggerLevel(String loggerName);

Source Link

Document

Gets the name of the log level associated with the specified logger.

Usage

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

protected void displayPage(final HttpServletRequest req, HttpServletResponse resp, final boolean posted)
        throws ServletException, IOException {
    writeTemplate(resp, new Closure<StringTemplate>() {
        @Override//from   w w  w  . java2  s.c  o  m
        public void execute(StringTemplate stringTemplate) {
            LoggingMXBean logBean = LogManager.getLoggingMXBean();

            if (posted) {
                String loggerName = req.getParameter("logger");
                String loggerLevel = req.getParameter("level");
                if (loggerName != null && loggerLevel != null) {
                    Logger logger = Logger.getLogger(loggerName);
                    Level newLevel = loggerLevel.equals("INHERIT") ? null : Level.parse(loggerLevel);
                    logger.setLevel(newLevel);
                    if (newLevel != null) {
                        maybeAdjustHandlerLevels(logger, newLevel);
                    }

                    stringTemplate.setAttribute("configChange",
                            String.format("%s level changed to %s", loggerName, loggerLevel));
                }
            }

            List<LoggerConfig> loggerConfigs = Lists.newArrayList();
            for (String logger : Ordering.natural().immutableSortedCopy(logBean.getLoggerNames())) {
                loggerConfigs.add(new LoggerConfig(logger, logBean.getLoggerLevel(logger)));
            }

            stringTemplate.setAttribute("loggers", loggerConfigs);
            stringTemplate.setAttribute("levels", LOG_LEVELS);
        }
    });
}

From source file:org.apache.aurora.common.net.http.handlers.LogConfig.java

protected String displayPage(Optional<String> configChange) throws TemplateException {
    StringWriter writer = new StringWriter();

    template.writeTemplate(writer, new Closure<StringTemplate>() {
        @Override/*from w  w  w. j  a v a  2 s  . c o  m*/
        public void execute(StringTemplate stringTemplate) {
            LoggingMXBean logBean = LogManager.getLoggingMXBean();

            if (configChange.isPresent()) {
                stringTemplate.setAttribute("configChange", configChange.get());
            }

            List<LoggerConfig> loggerConfigs = Lists.newArrayList();
            for (String logger : Ordering.natural().immutableSortedCopy(logBean.getLoggerNames())) {
                loggerConfigs.add(new LoggerConfig(logger, logBean.getLoggerLevel(logger)));
            }

            stringTemplate.setAttribute("loggers", loggerConfigs);
            stringTemplate.setAttribute("levels", LOG_LEVELS);
        }
    });

    return writer.toString();
}