Class StatusLoggerAdmin
- java.lang.Object
-
- javax.management.NotificationBroadcasterSupport
-
- org.apache.logging.log4j.core.jmx.StatusLoggerAdmin
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.util.EventListener
,javax.management.NotificationBroadcaster
,javax.management.NotificationEmitter
,StatusLoggerAdminMBean
,StatusListener
public class StatusLoggerAdmin extends javax.management.NotificationBroadcasterSupport implements StatusListener, StatusLoggerAdminMBean
Implementation of theStatusLoggerAdminMBean
interface.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
contextName
private Level
level
private javax.management.ObjectName
objectName
private java.util.concurrent.atomic.AtomicLong
sequenceNo
-
Fields inherited from interface org.apache.logging.log4j.core.jmx.StatusLoggerAdminMBean
NOTIF_TYPE_DATA, NOTIF_TYPE_MESSAGE, PATTERN
-
-
Constructor Summary
Constructors Constructor Description StatusLoggerAdmin(java.lang.String contextName, java.util.concurrent.Executor executor)
Constructs a newStatusLoggerAdmin
with theExecutor
to be used for sendingNotification
s asynchronously to listeners.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private static javax.management.MBeanNotificationInfo
createNotificationInfo()
java.lang.String
getContextName()
Returns the name of the LoggerContext that theStatusLogger
is associated with.java.lang.String
getLevel()
Returns theStatusLogger
level as a String.javax.management.ObjectName
getObjectName()
Returns theObjectName
of this mbean.java.util.List<StatusData>
getStatusData()
Returns a list with the most recentStatusData
objects in the status history.java.lang.String[]
getStatusDataHistory()
Returns a string array with the most recent messages in the status history.Level
getStatusLevel()
Return the Log Level that this listener wants included.void
log(StatusData data)
Called as events occur to process the StatusData.private long
nextSeqNo()
private long
nowMillis()
private void
removeListeners(java.lang.String ctxName)
Add listener to StatusLogger for this context, or replace it if it already exists.void
setLevel(java.lang.String level)
Sets theStatusLogger
level to the specified value.
-
-
-
Field Detail
-
sequenceNo
private final java.util.concurrent.atomic.AtomicLong sequenceNo
-
objectName
private final javax.management.ObjectName objectName
-
contextName
private final java.lang.String contextName
-
level
private Level level
-
-
Constructor Detail
-
StatusLoggerAdmin
public StatusLoggerAdmin(java.lang.String contextName, java.util.concurrent.Executor executor)
Constructs a newStatusLoggerAdmin
with theExecutor
to be used for sendingNotification
s 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 Detail
-
removeListeners
private void removeListeners(java.lang.String ctxName)
Add listener to StatusLogger for this context, or replace it if it already exists.- Parameters:
ctxName
-
-
createNotificationInfo
private static javax.management.MBeanNotificationInfo createNotificationInfo()
-
getStatusDataHistory
public java.lang.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 interfaceStatusLoggerAdminMBean
- Returns:
- the most recent messages logged by the
StatusLogger
.
-
getStatusData
public java.util.List<StatusData> getStatusData()
Description copied from interface:StatusLoggerAdminMBean
Returns a list with the most recentStatusData
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
Throwable
s 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
Throwable
s in their classpath.- Specified by:
getStatusData
in interfaceStatusLoggerAdminMBean
- Returns:
- the most recent messages logged by the
StatusLogger
.
-
getLevel
public java.lang.String getLevel()
Description copied from interface:StatusLoggerAdminMBean
Returns theStatusLogger
level as a String.- Specified by:
getLevel
in interfaceStatusLoggerAdminMBean
- 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 interfaceStatusListener
- Returns:
- the Log Level.
-
setLevel
public void setLevel(java.lang.String level)
Description copied from interface:StatusLoggerAdminMBean
Sets theStatusLogger
level to the specified value.- Specified by:
setLevel
in interfaceStatusLoggerAdminMBean
- Parameters:
level
- the newStatusLogger
level.
-
getContextName
public java.lang.String getContextName()
Description copied from interface:StatusLoggerAdminMBean
Returns the name of the LoggerContext that theStatusLogger
is associated with.- Specified by:
getContextName
in interfaceStatusLoggerAdminMBean
- 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 interfaceStatusListener
- Parameters:
data
- The StatusData for the event.
-
getObjectName
public javax.management.ObjectName getObjectName()
Returns theObjectName
of this mbean.- Specified by:
getObjectName
in interfaceStatusLoggerAdminMBean
- Returns:
- the
ObjectName
- See Also:
StatusLoggerAdminMBean.PATTERN
-
nextSeqNo
private long nextSeqNo()
-
nowMillis
private long nowMillis()
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-