Class LoggerConfig
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilterable
org.apache.logging.log4j.core.config.LoggerConfig
- All Implemented Interfaces:
Filterable
,LocationAware
,LifeCycle
,LifeCycle2
- Direct Known Subclasses:
AsyncLoggerConfig
,AsyncLoggerConfig.RootLogger
,LoggerConfig.RootLogger
@Plugin(name="Logger",
category="Core",
printObject=true)
public class LoggerConfig
extends AbstractFilterable
implements LocationAware
Logger object that is created via configuration.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
LoggerConfig.Builder<B extends LoggerConfig.Builder<B>>
Builds LoggerConfig instances.protected static class
protected static enum
static class
The root Logger.Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
Field Summary
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
Constructor Summary
ModifierConstructorDescriptionDefault constructor.protected
LoggerConfig
(String name, List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation) LoggerConfig
(String name, Level level, boolean additive) Constructor that sets the name, level and additive values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAppender
(Appender appender, Level level, Filter filter) Adds an Appender to the LoggerConfig.protected void
callAppenders
(LogEvent event) protected void
Removes all Appenders.static LoggerConfig
createLogger
(boolean additivity, Level level, String loggerName, String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter) Deprecated.static LoggerConfig
createLogger
(String additivity, Level level, String loggerName, String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter) Deprecated.Returns the Appender references.Returns all Appenders as a Map.Allows callers to determine the Level assigned to this LoggerConfig.Returns the Filter.getLevel()
Returns the logging Level.protected static LoggerConfig.LevelAndRefs
getLevelAndRefs
(Level level, AppenderRef[] refs, String levelAndRefs, Configuration config) Returns the LogEventFactory.getName()
Returns the name of the LoggerConfig.Returns the parent of this LoggerConfig.Deprecated.usegetPropertyList()
insteadReturns an unmodifiable list with the configuration properties, ornull
if thisLoggerConfig
does not have any configuration properties.Returns the object responsible for ensuring log events are delivered to a working appender, even during or after a reconfiguration.protected final boolean
protected static boolean
includeLocation
(String includeLocationConfigValue) protected static boolean
includeLocation
(String includeLocationConfigValue, Configuration configuration) boolean
Returns the valid of the additive flag.boolean
Returns the value of logger configuration attributeincludeLocation
, or, if no such attribute was configured,true
if logging is synchronous orfalse
if logging is asynchronous.boolean
void
log
(String loggerName, String fqcn, StackTraceElement location, Marker marker, Level level, Message data, Throwable t) Logs an event.void
Logs an event.void
Logs an event.protected void
log
(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate) Logs an event.static <B extends LoggerConfig.Builder<B>>
Bprotected void
processLogEvent
(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate) Logs an event, bypassing filters.void
removeAppender
(String name) Removes the Appender with the specific name.boolean
void
setAdditive
(boolean additive) Sets the additive setting.void
Sets the logging Level.void
setLogEventFactory
(LogEventFactory logEventFactory) Sets the LogEventFactory.void
setParent
(LoggerConfig parent) Sets the parent of this LoggerConfig.toString()
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, start, stop, stop
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
Field Details
-
ROOT
- See Also:
-
-
Constructor Details
-
LoggerConfig
public LoggerConfig()Default constructor. -
LoggerConfig
Constructor that sets the name, level and additive values.- Parameters:
name
- The Logger name.level
- The Level.additive
- true if the Logger is additive, false otherwise.
-
LoggerConfig
protected LoggerConfig(String name, List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation)
-
-
Method Details
-
newBuilder
-
getFilter
Description copied from class:AbstractFilterable
Returns the Filter.- Specified by:
getFilter
in interfaceFilterable
- Overrides:
getFilter
in classAbstractFilterable
- Returns:
- the Filter or null.
-
getName
Returns the name of the LoggerConfig.- Returns:
- the name of the LoggerConfig.
-
setParent
Sets the parent of this LoggerConfig.- Parameters:
parent
- the parent LoggerConfig.
-
getParent
Returns the parent of this LoggerConfig.- Returns:
- the LoggerConfig that is the parent of this one.
-
addAppender
Adds an Appender to the LoggerConfig.- Parameters:
appender
- The Appender to add.level
- The Level to use.filter
- A Filter for the Appender reference.
-
removeAppender
Removes the Appender with the specific name.- Parameters:
name
- The name of the Appender.
-
getAppenders
Returns all Appenders as a Map.- Returns:
- a Map with the Appender name as the key and the Appender as the value.
-
clearAppenders
protected void clearAppenders()Removes all Appenders. -
getAppenderRefs
Returns the Appender references.- Returns:
- a List of all the Appender names attached to this LoggerConfig.
-
setLevel
Sets the logging Level.- Parameters:
level
- The logging Level.
-
getLevel
Returns the logging Level.- Returns:
- the logging Level.
-
getExplicitLevel
Allows callers to determine the Level assigned to this LoggerConfig.- Returns:
- the Level associated with this LoggerConfig or null if none is set.
-
getLogEventFactory
Returns the LogEventFactory.- Returns:
- the LogEventFactory.
-
setLogEventFactory
Sets the LogEventFactory. Usually the LogEventFactory will be this LoggerConfig.- Parameters:
logEventFactory
- the LogEventFactory.
-
isAdditive
public boolean isAdditive()Returns the valid of the additive flag.- Returns:
- true if the LoggerConfig is additive, false otherwise.
-
setAdditive
public void setAdditive(boolean additive) Sets the additive setting.- Parameters:
additive
- true if the LoggerConfig should be additive, false otherwise.
-
isIncludeLocation
public boolean isIncludeLocation()Returns the value of logger configuration attributeincludeLocation
, or, if no such attribute was configured,true
if logging is synchronous orfalse
if logging is asynchronous.- Returns:
- whether location should be passed downstream
-
getProperties
Deprecated.usegetPropertyList()
insteadReturns an unmodifiable map with the configuration properties, ornull
if thisLoggerConfig
does not have any configuration properties.For each
Property
key in the map, the value istrue
if the property value has a variable that needs to be substituted.- Returns:
- an unmodifiable map with the configuration properties, or
null
- See Also:
-
getPropertyList
Returns an unmodifiable list with the configuration properties, ornull
if thisLoggerConfig
does not have any configuration properties.Each
Property
in the list has an attributevalueNeedsLookup
that istrue
if the property value has a variable that needs to be substituted.- Returns:
- an unmodifiable list with the configuration properties, or
null
- Since:
- 2.7
- See Also:
-
isPropertiesRequireLookup
public boolean isPropertiesRequireLookup() -
log
public void log(String loggerName, String fqcn, Marker marker, Level level, Message data, Throwable t) Logs an event.- Parameters:
loggerName
- The name of the Logger.fqcn
- The fully qualified class name of the caller.marker
- A Marker or null if none is present.level
- The event Level.data
- The Message.t
- A Throwable or null.
-
log
public void log(String loggerName, String fqcn, StackTraceElement location, Marker marker, Level level, Message data, Throwable t) Logs an event.- Parameters:
loggerName
- The name of the Logger.fqcn
- The fully qualified class name of the caller.location
- the location of the caller.marker
- A Marker or null if none is present.level
- The event Level.data
- The Message.t
- A Throwable or null.
-
log
Logs an event.- Parameters:
event
- The log event.
-
log
Logs an event.- Parameters:
event
- The log event.predicate
- predicate for which LoggerConfig instances to append to. A null value is equivalent to a true predicate.
-
getReliabilityStrategy
Returns the object responsible for ensuring log events are delivered to a working appender, even during or after a reconfiguration.- Returns:
- the object responsible for delivery of log events to the appender
-
processLogEvent
Logs an event, bypassing filters.- Parameters:
event
- The log event.predicate
- predicate for which LoggerConfig instances to append to. A null value is equivalent to a true predicate.
-
requiresLocation
public boolean requiresLocation()- Specified by:
requiresLocation
in interfaceLocationAware
-
callAppenders
-
toString
-
createLogger
@Deprecated public static LoggerConfig createLogger(String additivity, Level level, @PluginAttribute("name") String loggerName, String includeLocation, AppenderRef[] refs, Property[] properties, @PluginConfiguration Configuration config, Filter filter) Deprecated.Factory method to create a LoggerConfig.- Parameters:
additivity
- True if additive, false otherwise.level
- The Level to be associated with the Logger.loggerName
- The name of the Logger.includeLocation
- whether location should be passed downstreamrefs
- An array of Appender names.properties
- Properties to pass to the Logger.config
- The Configuration.filter
- A Filter.- Returns:
- A new LoggerConfig.
-
createLogger
@Deprecated public static LoggerConfig createLogger(@PluginAttribute(value="additivity",defaultBoolean=true) boolean additivity, @PluginAttribute("level") Level level, @Required(message="Loggers cannot be configured without a name") @PluginAttribute("name") String loggerName, @PluginAttribute("includeLocation") String includeLocation, @PluginElement("AppenderRef") AppenderRef[] refs, @PluginElement("Properties") Property[] properties, @PluginConfiguration Configuration config, @PluginElement("Filter") Filter filter) Deprecated.Factory method to create a LoggerConfig.- Parameters:
additivity
- true if additive, false otherwise.level
- The Level to be associated with the Logger.loggerName
- The name of the Logger.includeLocation
- whether location should be passed downstreamrefs
- An array of Appender names.properties
- Properties to pass to the Logger.config
- The Configuration.filter
- A Filter.- Returns:
- A new LoggerConfig.
- Since:
- 2.6
-
includeLocation
-
includeLocation
protected static boolean includeLocation(String includeLocationConfigValue, Configuration configuration) -
hasAppenders
protected final boolean hasAppenders() -
getLevelAndRefs
protected static LoggerConfig.LevelAndRefs getLevelAndRefs(Level level, AppenderRef[] refs, String levelAndRefs, Configuration config)
-
createLogger(boolean, Level, String, String, AppenderRef[], Property[], Configuration, Filter)