logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhelyazko Chobantonov" <zchobanto...@echo-inc.com>
Subject Incomplete LoggerDynamicMBean JMX operations - Unable to add/remove appender(s) from logger
Date Tue, 22 May 2007 00:29:26 GMT
Log4J Development Team,
 
I noticed that the operations in LoggerDynamicMBean are incomplete.
There is no way to change the list of appenders for given logger
(add/remove appenders)

It has only one operation addAppender which takes appender name and
appender class then create an appender from this class and add the
appender to the logger
But the appender at this point may not have been initialized
 
I think that this method should be renamed to createAppender - which do
everything except adding the appender to the logger (up to the creation
of the MBean for this appender)
Also there is no removeAppender operation nor addAppender from already
existing appenders
My suggestion is to add managedObject attribute to each Mbean that
export directly the log4j object (Appender, Logger, etc)
 
Here is my example of add/remove methods:
 
 boolean addAppender(String name) {
    cat.debug("addAppender called with " + name);
    try {
      ObjectName appender = new ObjectName("log4j", "appender", name);
      Appender managedObject = (Appender)server.getAttribute(appender,
"managedObject");
      logger.addAppender(managedObject);
      MBeanAttributeInfo attribute = null; 
      String attributeName = "appender=" + name;
      for (Iterator i = dAttributes.iterator(); i.hasNext(); ) {
        MBeanAttributeInfo attributeInfo = (MBeanAttributeInfo)i.next();
        if (attributeName.equals(attributeInfo.getName())) {
          attribute = attributeInfo; 
        }
      }
      if (attribute == null) {
        dAttributes.add(new MBeanAttributeInfo("appender=" + name,
"javax.management.ObjectName", "The "
            + name + " appender.", true, false, false));
      }
      return true;
    } catch (InstanceNotFoundException ex) {
    } catch (MalformedObjectNameException ex) {
    } catch (AttributeNotFoundException ex) {
    } catch (MBeanException ex) {
    } catch (ReflectionException ex) {
    }
    return false;
  }
 
  boolean removeAppender(String appenderName) {
    cat.debug("removeAppender called with " + appenderName);
    Appender appender = logger.getAppender(appenderName);
    if (appender != null) {
      logger.removeAppender(appender);
      MBeanAttributeInfo attribute = null; 
      String attributeName = "appender=" + appenderName;
      for (Iterator i = dAttributes.iterator(); i.hasNext(); ) {
        MBeanAttributeInfo attributeInfo = (MBeanAttributeInfo)i.next();
        if (attributeName.equals(attributeInfo.getName())) {
          attribute = attributeInfo; 
        }
      }
      if (attribute != null) {
        dAttributes.remove(attribute);
      }
      
      return true;
    }
    return false;
    // appenderMBeanRegistration();
  }
 
Thanks,
Zhelyazko Chobantonov

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


Mime
View raw message