Class StatusLoggerAdmin
java.lang.Object
javax.management.NotificationBroadcasterSupport
org.apache.logging.log4j.core.jmx.StatusLoggerAdmin
- All Implemented Interfaces:
Closeable, AutoCloseable, EventListener, MBeanRegistration, NotificationBroadcaster, NotificationEmitter, StatusLoggerAdminMBean, StatusListener
public class StatusLoggerAdmin
extends NotificationBroadcasterSupport
implements StatusListener, StatusLoggerAdminMBean, MBeanRegistration
Implementation of the
StatusLoggerAdminMBean interface.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate Levelprivate final ObjectNameprivate final AtomicLongprivate booleanprivate final LockFields inherited from interface StatusLoggerAdminMBean
NOTIF_TYPE_DATA, NOTIF_TYPE_MESSAGE, PATTERN -
Constructor Summary
ConstructorsConstructorDescriptionStatusLoggerAdmin(String contextName, Executor executor) Constructs a newStatusLoggerAdminwith theExecutorto be used for sendingNotifications asynchronously to listeners. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) BEGIN: ConditionalStatusListenerregistration ///////////////////////////////////////////////////////////////voidclose()private static MBeanNotificationInfoReturns the name of the LoggerContext that theStatusLoggeris associated with.getLevel()Returns theStatusLoggerlevel as a String.Returns theObjectNameof this mbean.Returns a list with the most recentStatusDataobjects in the status history.String[]END: ConditionalStatusListenerregistration /////////////////////////////////////////////////////////////////Return the Log Level that this listener wants included.voidlog(StatusData data) Called as events occur to process the StatusData.private longprivate longvoidvoidpostRegister(Boolean registrationDone) voidpreRegister(MBeanServer server, ObjectName name) voidSets theStatusLoggerlevel to the specified value.Methods inherited from class NotificationBroadcasterSupport
getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
-
Field Details
-
sequenceNo
-
objectName
-
contextName
-
level
-
statusListenerRegistered
private boolean statusListenerRegistered -
statusListenerRegistrationGuard
-
-
Constructor Details
-
StatusLoggerAdmin
Constructs a newStatusLoggerAdminwith theExecutorto be used for sendingNotifications 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
-
createNotificationInfo
-
addNotificationListener
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) BEGIN: ConditionalStatusListenerregistration ///////////////////////////////////////////////////////////////- Specified by:
addNotificationListenerin interfaceNotificationBroadcaster- Overrides:
addNotificationListenerin classNotificationBroadcasterSupport
-
preRegister
- Specified by:
preRegisterin interfaceMBeanRegistration
-
postRegister
- Specified by:
postRegisterin interfaceMBeanRegistration
-
preDeregister
public void preDeregister()- Specified by:
preDeregisterin interfaceMBeanRegistration
-
postDeregister
public void postDeregister()- Specified by:
postDeregisterin interfaceMBeanRegistration
-
getStatusDataHistory
END: ConditionalStatusListenerregistration /////////////////////////////////////////////////////////////////- Specified by:
getStatusDataHistoryin interfaceStatusLoggerAdminMBean- Returns:
- the most recent messages logged by the
StatusLogger.
-
getStatusData
Description copied from interface:StatusLoggerAdminMBeanReturns a list with the most recentStatusDataobjects 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:
getStatusDatain interfaceStatusLoggerAdminMBean- Returns:
- the most recent messages logged by the
StatusLogger.
-
getLevel
Description copied from interface:StatusLoggerAdminMBeanReturns theStatusLoggerlevel as a String.- Specified by:
getLevelin interfaceStatusLoggerAdminMBean- Returns:
- the
StatusLoggerlevel.
-
getStatusLevel
Description copied from interface:StatusListenerReturn the Log Level that this listener wants included.- Specified by:
getStatusLevelin interfaceStatusListener- Returns:
- the Log Level.
-
setLevel
Description copied from interface:StatusLoggerAdminMBeanSets theStatusLoggerlevel to the specified value.- Specified by:
setLevelin interfaceStatusLoggerAdminMBean- Parameters:
level- the newStatusLoggerlevel.
-
getContextName
Description copied from interface:StatusLoggerAdminMBeanReturns the name of the LoggerContext that theStatusLoggeris associated with.- Specified by:
getContextNamein interfaceStatusLoggerAdminMBean- Returns:
- logger context name
-
log
Description copied from interface:StatusListenerCalled as events occur to process the StatusData.- Specified by:
login interfaceStatusListener- Parameters:
data- The StatusData for the event.
-
getObjectName
Returns theObjectNameof this mbean.- Specified by:
getObjectNamein interfaceStatusLoggerAdminMBean- Returns:
- the
ObjectName - See Also:
-
nextSeqNo
private long nextSeqNo() -
nowMillis
private long nowMillis() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-