You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Giriraj Vengurleker <gv...@serus.com> on 2007/01/09 19:45:53 UTC
JMX and log4j
Hi
I am trying to register the Logger MBeans using the following code : However
I get exceptions pointing out that some of them are already registered. This
is despite my check for existing MBeans.
Also, the exception seems harmless but there is no way to suppress it.
Can someone please advise? Ideally I would like to know why I get the
exceptions.
Thanks
public static void loadMBeans() {
try {
// Create and Register the top level Log4J MBean
HierarchyDynamicMBean hdm = new
HierarchyDynamicMBean();
ObjectName mbo = new
ObjectName("log4j:hiearchy=default");
SerusJMXAgent.getAgent().registerMBean(mbo, hdm);
// Add the root logger to the Hierarchy MBean
Logger rootLogger =
Logger.getRootLogger();
hdm.addLoggerMBean(rootLogger.getName());
// Get each logger from the Log4J Repository and add it to
// the Hierarchy MBean created above.
LoggerRepository r =
LogManager.getLoggerRepository();
java.util.Enumeration enum1 =
r.getCurrentLoggers();
Logger logger = null;
while (enum1.hasMoreElements()){
logger = (Logger)
enum1.nextElement();
ObjectName objn = new
ObjectName("log4j", "logger", logger.getName());
if(
!SerusJMXAgent.getAgent().existsBean(objn) ) {
hdm.addLoggerMBean(logger.getName());
}
}
}
catch(Exception ex){
log.error(ex.getMessage());
}
}