Class StatusLoggerAdmin

java.lang.Object
javax.management.NotificationBroadcasterSupport
org.apache.logging.log4j.core.jmx.StatusLoggerAdmin
All Implemented Interfaces:
Closeable, AutoCloseable, EventListener, NotificationBroadcaster, NotificationEmitter, StatusLoggerAdminMBean, StatusListener

public class StatusLoggerAdmin extends NotificationBroadcasterSupport implements StatusListener, StatusLoggerAdminMBean
Implementation of the StatusLoggerAdminMBean interface.
  • Field Details

    • sequenceNo

      private final AtomicLong sequenceNo
    • objectName

      private final ObjectName objectName
    • contextName

      private final String contextName
    • level

      private Level level
  • Constructor Details

    • StatusLoggerAdmin

      public StatusLoggerAdmin(String contextName, Executor executor)
      Constructs a new StatusLoggerAdmin with the Executor to be used for sending Notifications asynchronously to listeners.
      Parameters:
      contextName - name of the LoggerContext under which to register this StatusLoggerAdmin. Note that the StatusLogger may be registered multiple times, once for each LoggerContext. In web containers, each web application has its own LoggerContext and by associating the StatusLogger with the LoggerContext, all associated MBeans can be unloaded when the web application is undeployed.
      executor - used to send notifications asynchronously
  • Method Details

    • removeListeners

      private void removeListeners(String ctxName)
      Add listener to StatusLogger for this context, or replace it if it already exists.
      Parameters:
      ctxName -
    • createNotificationInfo

      private static MBeanNotificationInfo createNotificationInfo()
    • getStatusDataHistory

      public String[] getStatusDataHistory()
      Description copied from interface: StatusLoggerAdminMBean
      Returns a string array with the most recent messages in the status history. The list has up to 200 entries by default but the length can be configured with system property "log4j2.status.entries".
      Specified by:
      getStatusDataHistory in interface StatusLoggerAdminMBean
      Returns:
      the most recent messages logged by the StatusLogger.
    • getStatusData

      public List<StatusData> getStatusData()
      Description copied from interface: StatusLoggerAdminMBean
      Returns a list with the most recent StatusData objects in the status history. The list has up to 200 entries by default but the length can be configured with system property "log4j2.status.entries".

      Note that the returned objects may contain Throwables from external libraries.

      JMX clients calling this method must be prepared to deal with the errors that occur if they do not have the class definition for such Throwables in their classpath.

      Specified by:
      getStatusData in interface StatusLoggerAdminMBean
      Returns:
      the most recent messages logged by the StatusLogger.
    • getLevel

      public String getLevel()
      Description copied from interface: StatusLoggerAdminMBean
      Returns the StatusLogger level as a String.
      Specified by:
      getLevel in interface StatusLoggerAdminMBean
      Returns:
      the StatusLogger level.
    • getStatusLevel

      public Level getStatusLevel()
      Description copied from interface: StatusListener
      Return the Log Level that this listener wants included.
      Specified by:
      getStatusLevel in interface StatusListener
      Returns:
      the Log Level.
    • setLevel

      public void setLevel(String level)
      Description copied from interface: StatusLoggerAdminMBean
      Sets the StatusLogger level to the specified value.
      Specified by:
      setLevel in interface StatusLoggerAdminMBean
      Parameters:
      level - the new StatusLogger level.
    • getContextName

      public String getContextName()
      Description copied from interface: StatusLoggerAdminMBean
      Returns the name of the LoggerContext that the StatusLogger is associated with.
      Specified by:
      getContextName in interface StatusLoggerAdminMBean
      Returns:
      logger context name
    • log

      public void log(StatusData data)
      Description copied from interface: StatusListener
      Called as events occur to process the StatusData.
      Specified by:
      log in interface StatusListener
      Parameters:
      data - The StatusData for the event.
    • getObjectName

      public ObjectName getObjectName()
      Returns the ObjectName of this mbean.
      Specified by:
      getObjectName in interface StatusLoggerAdminMBean
      Returns:
      the ObjectName
      See Also:
    • nextSeqNo

      private long nextSeqNo()
    • nowMillis

      private long nowMillis()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException