0 Replies Latest reply: Jul 2, 2010 5:50 AM by 843798 RSS

    JMX-Log4j Appender problem

    843798
      Dear listers
      we wrote thefollowing code to log the loglevel's dynamically.
      Following is the code
      public class MyApp implements MyAppMBean {     
      private static Logger logger = Logger.getLogger(MyApp.class);
      public void go() throws Exception{
      while(true){
      logger.debug("DEBUG") ;
      logger.info("INFO") ;
      logger.warn("WARN");
      logger.error("ERROR");
      logger.fatal("FATAL");
      Thread.sleep(2000);
      }
      }
      public void setLoggingLevel(String level){
      logger.info("Setting logging level to: " + level);
      Level newLevel = Level.toLevel(level, Level.INFO);
      Logger.getRootLogger().setLevel(newLevel);
      }
      public String getLoggingLevel(){                       
      return Logger.getRootLogger().getLevel().toString() ;
      }
      public static void main(String[] args) throws Exception
      {                   
      DOMConfigurator.configure("log4j.xml");
      MyApp app = new MyApp();
      //Lookup for the mbean server
      MBeanServer server = ManagementFactory.getPlatformMBeanServer();
      //Create and register the top level log4j MBean
      HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
      ObjectName mbo = new ObjectName("log4j:logger=root");
      System.out.println("Debug10");
      server.registerMBean(hdm, mbo);
      LoggerRepository r = LogManager.getLoggerRepository();
      Enumeration<Logger> elogs = r.getCurrentLoggers();
      Logger logger = null;
      while(elogs.hasMoreElements())
      {
      //need to show the elements of teamcenter only.
      logger = (Logger)elogs.nextElement();
      hdm.addLoggerMBean(logger.getName());
      } System.out.println(Logger.getRootLogger().getLevel().toString());
      int portNumber=9999;
      ObjectName htmlName = new ObjectName("log4j:logger=root,port=" + portNumber) ;
      HtmlAdaptorServer html = new HtmlAdaptorServer(portNumber);
      html.setPort(portNumber);
      server.registerMBean(html, htmlName);
      html.start();
      app.go();
      }
      When setting the attributes for the appenders under log4j from htmladapter it gives the following message.
      *477 All Attributes Not Set*
      *1/8 attribute(s) were not set:*
      appender%3DTaskAppender%2Clayout%3Dorg.apache.log4j.PatternLayout

      Please advice how can we solve this issue ~Vilas