Class Log4jConfiguratorMBean

  • All Implemented Interfaces:
    java.lang.Cloneable, javax.management.DynamicMBean, CloneableDynamicMBean

    public class Log4jConfiguratorMBean
    extends java.lang.Object
    implements CloneableDynamicMBean
    MBean used to dynamically configure log4j. Simply all known and named loggers - including the root logger - are exposed as attributes of this MBean. The attribute's values represent the current level of the appropriate logger. Hint: This component itself uses log4j as the logging framework.
    Author:
    schwabmar
    See Also:
    Log4jConfigurator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ASTERISK
      Asterisk used as trailing string for inherited logging levels.
      static java.lang.String DEFAULT_JMX_NAME
      Default name.
    • Constructor Summary

      Constructors 
      Constructor Description
      Log4jConfiguratorMBean()
      Default constructor for Log4jConfiguratorMBean.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()
      Creates a clone of the object.
      java.lang.Object getAttribute​(java.lang.String attribute)
      Gets the value of an attribute and thus the level of a certain logger.
      javax.management.AttributeList getAttributes​(java.lang.String[] attributes)
      Gets the values of several attributes.
      javax.management.MBeanInfo getMBeanInfo()
      Returns all informations on the MBean, such as attributes and operations.
      java.lang.Object invoke​(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] signature)
      Invokes an operation on the MBean.
      void setAttribute​(javax.management.Attribute attribute)
      Sets the value of an attribute.
      javax.management.AttributeList setAttributes​(javax.management.AttributeList attributes)
      Sets the values of several attributes.
      java.lang.String setLoggerLevel​(java.lang.String pattern, java.lang.String level)
      Directly sets a level on one ore more loggers.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ASTERISK

        public static final java.lang.String ASTERISK
        Asterisk used as trailing string for inherited logging levels.
        See Also:
        Constant Field Values
      • DEFAULT_JMX_NAME

        public static final java.lang.String DEFAULT_JMX_NAME
        Default name. This is the value of the name part of this MBean's JMX object name.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Log4jConfiguratorMBean

        public Log4jConfiguratorMBean()
        Default constructor for Log4jConfiguratorMBean.
    • Method Detail

      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String attribute)
                                      throws javax.management.AttributeNotFoundException,
                                             javax.management.MBeanException,
                                             javax.management.ReflectionException
        Gets the value of an attribute and thus the level of a certain logger. If the logger hasn't got an assigned level, the level from the parent logger trailed with an asterisk is returned.
        Specified by:
        getAttribute in interface javax.management.DynamicMBean
        Throws:
        javax.management.AttributeNotFoundException
        javax.management.MBeanException
        javax.management.ReflectionException
        See Also:
        DynamicMBean.getAttribute(String)
      • setAttribute

        public void setAttribute​(javax.management.Attribute attribute)
                          throws javax.management.AttributeNotFoundException,
                                 javax.management.InvalidAttributeValueException,
                                 javax.management.MBeanException,
                                 javax.management.ReflectionException
        Sets the value of an attribute.
        Specified by:
        setAttribute in interface javax.management.DynamicMBean
        Throws:
        javax.management.AttributeNotFoundException
        javax.management.InvalidAttributeValueException
        javax.management.MBeanException
        javax.management.ReflectionException
        See Also:
        DynamicMBean.setAttribute(Attribute)
      • getAttributes

        public javax.management.AttributeList getAttributes​(java.lang.String[] attributes)
        Gets the values of several attributes. Delegates the work to the method getAttribute.
        Specified by:
        getAttributes in interface javax.management.DynamicMBean
        See Also:
        getAttribute(String), DynamicMBean.getAttributes(String[])
      • setAttributes

        public javax.management.AttributeList setAttributes​(javax.management.AttributeList attributes)
        Sets the values of several attributes. Delegates the work to the method setAttribute.
        Specified by:
        setAttributes in interface javax.management.DynamicMBean
        See Also:
        setAttribute(Attribute), DynamicMBean.setAttributes(AttributeList)
      • invoke

        public java.lang.Object invoke​(java.lang.String actionName,
                                       java.lang.Object[] params,
                                       java.lang.String[] signature)
                                throws javax.management.MBeanException,
                                       javax.management.ReflectionException
        Invokes an operation on the MBean. This method is generically implemented - it simply tries to call a method named <actionName> with the provided parameters.
        Specified by:
        invoke in interface javax.management.DynamicMBean
        Throws:
        javax.management.MBeanException
        javax.management.ReflectionException
        See Also:
        DynamicMBean.invoke(String, Object[], String[])
      • setLoggerLevel

        public java.lang.String setLoggerLevel​(java.lang.String pattern,
                                               java.lang.String level)
        Directly sets a level on one ore more loggers. Therefore the loggers to modify are selected via a pattern - all loggers with a name matching the provided pattern are set to the new level.
        Example: ^org\.swisspush\..* matches all names beginning with org.swisspush (this is the exact expression - in almost every case this expression can be simplified to ^org.swisspush.*).
        This method is only invoked by the invoke method of this class and has to be public (since it is called via reflection API).
        Parameters:
        pattern - Regular expression used to select the loggers.
        level - New level.
        Returns:
        The total number of modified loggers.
        See Also:
        Level, invoke(String, Object[], String[]), getOperationInfo()
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Creates a clone of the object.
        Specified by:
        clone in interface CloneableDynamicMBean
        Overrides:
        clone in class java.lang.Object
        Returns:
        The MBean's clone.
        Throws:
        java.lang.CloneNotSupportedException