Interface LoggerContextAdminMBean

  • All Known Implementing Classes:
    LoggerContextAdmin

    public interface LoggerContextAdminMBean
    The MBean interface for monitoring and managing a LoggerContext.
    • Field Detail

      • PATTERN

        static final String PATTERN
        ObjectName pattern ("org.apache.logging.log4j2:type=%s" ) for LoggerContextAdmin MBeans. This pattern contains a variable, which is the name of the logger context.

        You can find all registered LoggerContextAdmin MBeans like this:

         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
         String pattern = String.format(LoggerContextAdminMBean.PATTERN, "*");
         Set<ObjectName> loggerContextNames = mbs.queryNames(new ObjectName(pattern), null);
         

        Some characters are not allowed in ObjectNames. The logger context name may be quoted. When LoggerContextAdmin MBeans are registered, their ObjectNames are created using this pattern as follows:

         String ctxName = Server.escape(loggerContext.getName());
         String name = String.format(PATTERN, ctxName);
         ObjectName objectName = new ObjectName(name);
         
        See Also:
        Server.escape(String), Constant Field Values
      • NOTIF_TYPE_RECONFIGURED

        static final String NOTIF_TYPE_RECONFIGURED
        Notification that the Configuration of the instrumented LoggerContext has been reconfigured. Notifications of this type ("com.apache.logging.log4j.core.jmx.config.reconfigured" ) do not carry a message or user data.
        See Also:
        Constant Field Values
    • Method Detail

      • getObjectName

        ObjectName getObjectName()
        Returns the ObjectName that this MBean is registered with in the MBean server.
      • getStatus

        String getStatus()
        Returns the status of the instrumented LoggerContext.
        Returns:
        the LoggerContext status.
      • getName

        String getName()
        Returns the name of the instrumented LoggerContext.
        Returns:
        the name of the instrumented LoggerContext.
      • getConfigLocationUri

        String getConfigLocationUri()
        Returns the configuration location URI as a String.
        Returns:
        the configuration location
      • setConfigLocationUri

        void setConfigLocationUri​(String configLocation)
                           throws URISyntaxException,
                                  IOException
        Sets the configuration location to the specified URI. This will cause the instrumented LoggerContext to reconfigure.
        Parameters:
        configLocation - location of the configuration file in URI format.
        Throws:
        URISyntaxException - if the format of the specified configLocationURI is incorrect
        IOException - if an error occurred reading the specified location
      • getConfigText

        String getConfigText()
                      throws IOException
        Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call to setConfigText. If reading a file, this method assumes the file's character encoding is UTF-8.
        Returns:
        the configuration text
        Throws:
        IOException - if a problem occurred reading the contents of the config file.
      • getConfigText

        String getConfigText​(String charsetName)
                      throws IOException
        Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call to setConfigText.
        Parameters:
        charsetName - the encoding to use to convert the file's bytes into the resulting string.
        Returns:
        the configuration text
        Throws:
        IOException - if a problem occurred reading the contents of the config file.
      • setConfigText

        void setConfigText​(String configText,
                           String charsetName)
        Sets the configuration text. This does not replace the contents of the configuration file, but does cause the instrumented LoggerContext to be reconfigured with the specified text.
        Parameters:
        configText - the configuration text in XML or JSON format
        charsetName - name of the Charset used to convert the specified configText to bytes
        Throws:
        IllegalArgumentException - if a problem occurs configuring from the specified text
      • getConfigName

        String getConfigName()
        Returns the name of the Configuration of the instrumented LoggerContext.
        Returns:
        the Configuration name
      • getConfigClassName

        String getConfigClassName()
        Returns the class name of the Configuration of the instrumented LoggerContext.
        Returns:
        the class name of the Configuration.
      • getConfigFilter

        String getConfigFilter()
        Returns a string description of all Filters configured in the Configuration of the instrumented LoggerContext.
        Returns:
        a string description of all Filters configured
      • getConfigProperties

        Map<String,​String> getConfigProperties()
        Returns a map with configured properties.
        Returns:
        a map with configured properties.