public class LoggerContext extends AbstractLifeCycle implements org.apache.logging.log4j.spi.LoggerContext, ConfigurationListener
LifeCycle.State
Modifier and Type | Field and Description |
---|---|
static String |
PROPERTY_CONFIG |
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
Constructor and Description |
---|
LoggerContext(String name)
Constructor taking only a name.
|
LoggerContext(String name,
Object externalContext)
Constructor taking a name and a reference to an external context.
|
LoggerContext(String name,
Object externalContext,
String configLocn)
Constructor taking a name external context and a configuration location
String.
|
LoggerContext(String name,
Object externalContext,
URI configLocn)
Constructor taking a name, external context and a configuration URI.
|
Modifier and Type | Method and Description |
---|---|
void |
addFilter(Filter filter)
Adds a Filter to the Configuration.
|
void |
addPropertyChangeListener(PropertyChangeListener listener) |
URI |
getConfigLocation()
Returns the initial configuration location or
null . |
Configuration |
getConfiguration()
Returns the current Configuration.
|
Object |
getExternalContext()
Returns the external context.
|
Logger |
getLogger(String name)
Obtains a Logger from the Context.
|
Logger |
getLogger(String name,
org.apache.logging.log4j.message.MessageFactory messageFactory)
Obtains a Logger from the Context.
|
Collection<Logger> |
getLoggers()
Gets a collection of the current loggers.
|
String |
getName()
Gets the name.
|
boolean |
hasLogger(String name)
Determines if the specified Logger exists.
|
protected Logger |
newInstance(LoggerContext ctx,
String name,
org.apache.logging.log4j.message.MessageFactory messageFactory) |
void |
onChange(Reconfigurable reconfigurable)
Causes a reconfiguration to take place when the underlying configuration
file changes.
|
void |
reconfigure()
Reconfigure the context.
|
void |
removeFilter(Filter filter)
Removes a Filter from the current Configuration.
|
void |
removePropertyChangeListener(PropertyChangeListener listener) |
void |
setConfigLocation(URI configLocation)
Sets the configLocation to the specified value and reconfigures this context.
|
void |
setExternalContext(Object context)
Sets the external context.
|
void |
start() |
void |
start(Configuration config)
Starts with a specific configuration.
|
void |
stop() |
void |
updateLoggers()
Causes all Loggers to be updated against the current Configuration.
|
void |
updateLoggers(Configuration config)
Causes all Logger to be updated against the specified Configuration.
|
equalsImpl, getState, hashCodeImpl, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping
public static final String PROPERTY_CONFIG
public LoggerContext(String name)
name
- The context name.public LoggerContext(String name, Object externalContext)
name
- The context name.externalContext
- The external context.public LoggerContext(String name, Object externalContext, URI configLocn)
name
- The context name.externalContext
- The external context.configLocn
- The location of the configuration as a URI.public LoggerContext(String name, Object externalContext, String configLocn)
name
- The configuration location.externalContext
- The external context.configLocn
- The configuration location.public void start()
start
in interface LifeCycle
start
in class AbstractLifeCycle
public void start(Configuration config)
config
- The new Configuration.public void stop()
stop
in interface LifeCycle
stop
in class AbstractLifeCycle
public void setExternalContext(Object context)
context
- The external context.public Object getExternalContext()
getExternalContext
in interface org.apache.logging.log4j.spi.LoggerContext
public Logger getLogger(String name)
getLogger
in interface org.apache.logging.log4j.spi.LoggerContext
name
- The name of the Logger to return.public Collection<Logger> getLoggers()
Whether this collection is a copy of the underlying collection or not is undefined. Therefore, modify this collection at your own risk.
public Logger getLogger(String name, org.apache.logging.log4j.message.MessageFactory messageFactory)
getLogger
in interface org.apache.logging.log4j.spi.LoggerContext
name
- The name of the Logger to return.messageFactory
- The message factory is used only when creating a
logger, subsequent use does not change the logger but will log
a warning if mismatched.public boolean hasLogger(String name)
hasLogger
in interface org.apache.logging.log4j.spi.LoggerContext
name
- The Logger name to search for.public Configuration getConfiguration()
public void addFilter(Filter filter)
filter
- The Filter to add.public void removeFilter(Filter filter)
filter
- The Filter to remove.public void addPropertyChangeListener(PropertyChangeListener listener)
public void removePropertyChangeListener(PropertyChangeListener listener)
public URI getConfigLocation()
null
. The returned value may not be the location of the
current configuration. Use
getConfiguration()
.getConfigurationSource()
.getLocation()
to get the actual source of the current configuration.null
public void setConfigLocation(URI configLocation)
configLocation
- the location of the new configurationpublic void reconfigure()
public void updateLoggers()
public void updateLoggers(Configuration config)
config
- The Configuration.public void onChange(Reconfigurable reconfigurable)
onChange
in interface ConfigurationListener
reconfigurable
- The Configuration that can be reconfigured.protected Logger newInstance(LoggerContext ctx, String name, org.apache.logging.log4j.message.MessageFactory messageFactory)
Copyright © 1999-2021 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.