private void listLoggers(PrintStream out, PrintStream err) { out.println(" Level\t\tName"); Logger rootLogger = Logger.getRootLogger(); printLoggerInfo(rootLogger, out); Enumeration<?> enumerator = rootLogger.getLoggerRepository().getCurrentLoggers(); while (enumerator.hasMoreElements()) { printLoggerInfo((Logger) enumerator.nextElement(), out); } }
private void displayMatchingLoggersLevel(String loggerName, PrintStream out, PrintStream err) { String loggerPrefix = loggerName.substring(0, loggerName.length() - 1); out.println(" Level\t\tName"); Logger rootLogger = Logger.getRootLogger(); if (rootLogger.getName().startsWith(loggerPrefix)) printLoggerInfo(rootLogger, out); Enumeration<?> enumerator = rootLogger.getLoggerRepository().getCurrentLoggers(); while (enumerator.hasMoreElements()) { Logger logger = (Logger) enumerator.nextElement(); if (logger.getName().startsWith(loggerPrefix)) printLoggerInfo(logger, out); } }
/** * Registers a logger to the management server. * * @param logger A logger to be registered for management. */ public static synchronized void register(Logger logger) { try { ManagementFactory.getPlatformMBeanServer() .createMBean( "com.hapiware.jmx.log4j.Logging", new ObjectName(LOGGING_NAME), new Object[] {logger.getLoggerRepository()}, new String[] {"org.apache.log4j.spi.LoggerRepository"}); } catch (MBeanException e) { e.printStackTrace(); } catch (InstanceAlreadyExistsException e) { e.printStackTrace(); } catch (NotCompliantMBeanException e) { e.printStackTrace(); } catch (MalformedObjectNameException e) { e.printStackTrace(); } catch (ReflectionException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } }
public void tearDown() { root.getLoggerRepository().resetConfiguration(); }