You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2004/07/12 17:51:24 UTC

DO NOT REPLY [Bug 30055] New: - Problem with registering Appenders with the same name in the LoggerDynamicMBean

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30055>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30055

Problem with registering Appenders with the same name in the LoggerDynamicMBean

           Summary: Problem with registering Appenders with the same name in
                    the LoggerDynamicMBean
           Product: Log4j
           Version: unspecified
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Other
        AssignedTo: log4j-dev@jakarta.apache.org
        ReportedBy: noga@imperva.com


I'm creating a management system that includes using MBeans to manage the 
logger module. 

the logger is configured in an xml file and includes some appenders and some 
loggers that use these appenders.  loggers may use the same appenders. the 
appenders' name is used to compose it's ObjectName when registering it as an 
AppenderDynamicMBean. therefore, if 2 loggers use the same appender, they will 
both try to register them in the MBeanServer. as soon as the first request is 
made, all others will fail -due to the duplication of the ObjectName assigned 
for the MBean. and the problem occurs in the following code in 
LoggerDynamicMBean.java:

  void registerAppenderMBean(Appender appender) {
    String name = appender.getName();
    cat.debug("Adding AppenderMBean for appender named "+name);
    ObjectName objectName = null;
    try {
      AppenderDynamicMBean appenderMBean = new AppenderDynamicMBean(appender);
      objectName = new ObjectName("log4j", "appender", name);
      server.registerMBean(appenderMBean, objectName);

      dAttributes.add(new MBeanAttributeInfo("appender="+name,
					     "javax.management.ObjectName",
					     "The "+name+" appender.",
					     true,
					     true,
					     false));

    } catch(Exception e) {
      cat.error("Could not add appenderMBean for ["+name+"].", e);
    }
  }

The part when the second logger tries to register the appender, 
an "InstanceAlreadyExistsException" is thrown (which is ok) however the 
following line is not executed (which is not ok!). and the appender is never 
registered as the MBean's attribute!

I would suggest catch the "InstanceAlreadyExistsException" separately and when 
it is being caught - to still add the appender as the attribute of the 
LoggerDynamicMBean - that fact that it already exists on the MBeanServer does 
not mean it should not be registered as an attribute of the LoggerDynamicMBean.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org