Example usage for java.util.logging LogManager getLoggingMXBean

List of usage examples for java.util.logging LogManager getLoggingMXBean

Introduction

In this page you can find the example usage for java.util.logging LogManager getLoggingMXBean.

Prototype

@Deprecated(since = "9")
public static synchronized LoggingMXBean getLoggingMXBean() 

Source Link

Document

Returns LoggingMXBean for managing loggers.

Usage

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 .java  2 s .c  om*/
            "<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.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 ww . ja  v a 2  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:edu.usu.sdl.openstorefront.web.rest.service.Application.java

@GET
@RequireAdmin//from   w  ww . j  a  v  a 2 s  . com
@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.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  ww.j a  va2 s .  com
        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();
}