Package org.apache.log4j.jmx

Examples of org.apache.log4j.jmx.HierarchyDynamicMBean


  @SuppressWarnings("rawtypes")
  @Test
  public void testTrimming() throws Exception {
    File idxDir = getIdxDir();
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
    try {
      mbeanServer.registerMBean(hdm, new ObjectName("HouseGlass:name=log4j"));
      // Add the root logger to the Hierarchy MBean
      hdm.addLoggerMBean(Logger.getRootLogger().getName());

      // Get each logger from the Log4J Repository and add it to
      // the Hierarchy MBean created above.
      LoggerRepository r = LogManager.getLoggerRepository();

      java.util.Enumeration loggers = r.getCurrentLoggers();

      int count = 1;
      while (loggers.hasMoreElements()) {
        String name = ((Logger) loggers.nextElement()).getName();
        if (log.isDebugEnabled()) {
          log.debug("[contextInitialized]: Registering " + name);
        }
        hdm.addLoggerMBean(name);
        count++;
      }
      if (log.isInfoEnabled()) {
        log.info("[contextInitialized]: " + count + " log4j MBeans registered.");
      }
View Full Code Here

TOP

Related Classes of org.apache.log4j.jmx.HierarchyDynamicMBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.