Class LoggerContextAdmin
- java.lang.Object
-
- javax.management.NotificationBroadcasterSupport
-
- org.apache.logging.log4j.core.jmx.LoggerContextAdmin
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.util.EventListener
,javax.management.NotificationBroadcaster
,javax.management.NotificationEmitter
,LoggerContextAdminMBean
public class LoggerContextAdmin extends javax.management.NotificationBroadcasterSupport implements LoggerContextAdminMBean, java.beans.PropertyChangeListener
Implementation of theLoggerContextAdminMBean
interface.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BUFFER_SIZE
private static StatusLogger
LOGGER
private LoggerContext
loggerContext
private javax.management.ObjectName
objectName
private static int
PAGE
private java.util.concurrent.atomic.AtomicLong
sequenceNo
private static int
TEXT_BUFFER
-
Fields inherited from interface org.apache.logging.log4j.core.jmx.LoggerContextAdminMBean
NOTIF_TYPE_RECONFIGURED, PATTERN
-
-
Constructor Summary
Constructors Constructor Description LoggerContextAdmin(LoggerContext loggerContext, java.util.concurrent.Executor executor)
Constructs a newLoggerContextAdmin
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 private static javax.management.MBeanNotificationInfo
createNotificationInfo()
private Configuration
getConfig()
java.lang.String
getConfigClassName()
Returns the class name of theConfiguration
of the instrumented LoggerContext.java.lang.String
getConfigFilter()
Returns a string description of all Filters configured in theConfiguration
of the instrumented LoggerContext.java.lang.String
getConfigLocationUri()
Returns the configuration location URI as a String.java.lang.String
getConfigName()
Returns the name of the Configuration of the instrumented LoggerContext.java.util.Map<java.lang.String,java.lang.String>
getConfigProperties()
Returns a map with configured properties.java.lang.String
getConfigText()
Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText
.java.lang.String
getConfigText(java.lang.String charsetName)
Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText
.java.lang.String
getName()
Returns the name of the instrumentedLoggerContext
.javax.management.ObjectName
getObjectName()
Returns theObjectName
of this mbean.java.lang.String
getStatus()
Returns the status of the instrumentedLoggerContext
.private long
nextSeqNo()
private long
now()
void
propertyChange(java.beans.PropertyChangeEvent evt)
private java.lang.String
readContents(java.io.InputStream in, java.nio.charset.Charset charset)
Returns the contents of the specified input stream as a String.void
setConfigLocationUri(java.lang.String configLocation)
Sets the configuration location to the specified URI.void
setConfigText(java.lang.String configText, java.lang.String charsetName)
Sets the configuration text.
-
-
-
Field Detail
-
PAGE
private static final int PAGE
- See Also:
- Constant Field Values
-
TEXT_BUFFER
private static final int TEXT_BUFFER
- See Also:
- Constant Field Values
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
LOGGER
private static final StatusLogger LOGGER
-
sequenceNo
private final java.util.concurrent.atomic.AtomicLong sequenceNo
-
objectName
private final javax.management.ObjectName objectName
-
loggerContext
private final LoggerContext loggerContext
-
-
Constructor Detail
-
LoggerContextAdmin
public LoggerContextAdmin(LoggerContext loggerContext, java.util.concurrent.Executor executor)
Constructs a newLoggerContextAdmin
with theExecutor
to be used for sendingNotification
s asynchronously to listeners.- Parameters:
executor
- used to send notifications asynchronouslyloggerContext
- the instrumented object
-
-
Method Detail
-
createNotificationInfo
private static javax.management.MBeanNotificationInfo createNotificationInfo()
-
getStatus
public java.lang.String getStatus()
Description copied from interface:LoggerContextAdminMBean
Returns the status of the instrumentedLoggerContext
.- Specified by:
getStatus
in interfaceLoggerContextAdminMBean
- Returns:
- the LoggerContext status.
-
getName
public java.lang.String getName()
Description copied from interface:LoggerContextAdminMBean
Returns the name of the instrumentedLoggerContext
.- Specified by:
getName
in interfaceLoggerContextAdminMBean
- Returns:
- the name of the instrumented
LoggerContext
.
-
getConfig
private Configuration getConfig()
-
getConfigLocationUri
public java.lang.String getConfigLocationUri()
Description copied from interface:LoggerContextAdminMBean
Returns the configuration location URI as a String.- Specified by:
getConfigLocationUri
in interfaceLoggerContextAdminMBean
- Returns:
- the configuration location
-
setConfigLocationUri
public void setConfigLocationUri(java.lang.String configLocation) throws java.net.URISyntaxException, java.io.IOException
Description copied from interface:LoggerContextAdminMBean
Sets the configuration location to the specified URI. This will cause the instrumentedLoggerContext
to reconfigure.- Specified by:
setConfigLocationUri
in interfaceLoggerContextAdminMBean
- Parameters:
configLocation
- location of the configuration file inURI
format.- Throws:
java.net.URISyntaxException
- if the format of the specified configLocationURI is incorrectjava.io.IOException
- if an error occurred reading the specified location
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
getConfigText
public java.lang.String getConfigText() throws java.io.IOException
Description copied from interface:LoggerContextAdminMBean
Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText
. If reading a file, this method assumes the file's character encoding is UTF-8.- Specified by:
getConfigText
in interfaceLoggerContextAdminMBean
- Returns:
- the configuration text
- Throws:
java.io.IOException
- if a problem occurred reading the contents of the config file.
-
getConfigText
public java.lang.String getConfigText(java.lang.String charsetName) throws java.io.IOException
Description copied from interface:LoggerContextAdminMBean
Returns the configuration text, which may be the contents of the configuration file or the text that was last set with a call tosetConfigText
.- Specified by:
getConfigText
in interfaceLoggerContextAdminMBean
- Parameters:
charsetName
- the encoding to use to convert the file's bytes into the resulting string.- Returns:
- the configuration text
- Throws:
java.io.IOException
- if a problem occurred reading the contents of the config file.
-
readContents
private java.lang.String readContents(java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOException
Returns the contents of the specified input stream as a String.- Parameters:
in
- stream to read fromcharset
- MUST not be null- Returns:
- stream contents
- Throws:
java.io.IOException
- if a problem occurred reading from the stream.
-
setConfigText
public void setConfigText(java.lang.String configText, java.lang.String charsetName)
Description copied from interface:LoggerContextAdminMBean
Sets the configuration text. This does not replace the contents of the configuration file, but does cause the instrumentedLoggerContext
to be reconfigured with the specified text.- Specified by:
setConfigText
in interfaceLoggerContextAdminMBean
- Parameters:
configText
- the configuration text in XML or JSON formatcharsetName
- name of theCharset
used to convert the specified configText to bytes
-
getConfigName
public java.lang.String getConfigName()
Description copied from interface:LoggerContextAdminMBean
Returns the name of the Configuration of the instrumented LoggerContext.- Specified by:
getConfigName
in interfaceLoggerContextAdminMBean
- Returns:
- the Configuration name
-
getConfigClassName
public java.lang.String getConfigClassName()
Description copied from interface:LoggerContextAdminMBean
Returns the class name of theConfiguration
of the instrumented LoggerContext.- Specified by:
getConfigClassName
in interfaceLoggerContextAdminMBean
- Returns:
- the class name of the
Configuration
.
-
getConfigFilter
public java.lang.String getConfigFilter()
Description copied from interface:LoggerContextAdminMBean
Returns a string description of all Filters configured in theConfiguration
of the instrumented LoggerContext.- Specified by:
getConfigFilter
in interfaceLoggerContextAdminMBean
- Returns:
- a string description of all Filters configured
-
getConfigProperties
public java.util.Map<java.lang.String,java.lang.String> getConfigProperties()
Description copied from interface:LoggerContextAdminMBean
Returns a map with configured properties.- Specified by:
getConfigProperties
in interfaceLoggerContextAdminMBean
- Returns:
- a map with configured properties.
-
getObjectName
public javax.management.ObjectName getObjectName()
Returns theObjectName
of this mbean.- Specified by:
getObjectName
in interfaceLoggerContextAdminMBean
- Returns:
- the
ObjectName
- See Also:
LoggerContextAdminMBean.PATTERN
-
nextSeqNo
private long nextSeqNo()
-
now
private long now()
-
-