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
Nested Classes Modifier and Type Class Description static classLoggerConfig.Builder<B extends LoggerConfig.Builder<B>>Builds LoggerConfig instances.protected static classLoggerConfig.LevelAndRefsprotected static classLoggerConfig.LoggerConfigPredicatestatic classLoggerConfig.RootLoggerThe root Logger.-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
Fields Modifier and Type Field Description private booleanadditiveprivate java.util.List<AppenderRef>appenderRefsprivate AppenderControlArraySetappendersprivate Configurationconfigprivate booleanincludeLocationprivate Levellevelprivate static LogEventFactoryLOG_EVENT_FACTORYprivate LogEventFactorylogEventFactoryprivate java.lang.Stringnameprivate LoggerConfigparentprivate java.util.List<Property>propertiesprivate java.util.Map<Property,java.lang.Boolean>propertiesMapprivate booleanpropertiesRequireLookupprivate ReliabilityStrategyreliabilityStrategystatic java.lang.StringROOT-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
-
Constructor Summary
Constructors Modifier Constructor Description LoggerConfig()Default constructor.protectedLoggerConfig(java.lang.String name, java.util.List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation)LoggerConfig(java.lang.String name, Level level, boolean additive)Constructor that sets the name, level and additive values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAppender(Appender appender, Level level, Filter filter)Adds an Appender to the LoggerConfig.protected voidcallAppenders(LogEvent event)private voidcleanupFilter(AppenderControl ctl)protected voidclearAppenders()Removes all Appenders.private static booleancontainsPropertyRequiringLookup(Property[] properties)static LoggerConfigcreateLogger(boolean additivity, Level level, java.lang.String loggerName, java.lang.String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter)Deprecated.static LoggerConfigcreateLogger(java.lang.String additivity, Level level, java.lang.String loggerName, java.lang.String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter)Deprecated.java.util.List<AppenderRef>getAppenderRefs()Returns the Appender references.java.util.Map<java.lang.String,Appender>getAppenders()Returns all Appenders as a Map.LevelgetExplicitLevel()Allows callers to determine the Level assigned to this LoggerConfig.FiltergetFilter()Returns the Filter.LevelgetLevel()Returns the logging Level.protected static LoggerConfig.LevelAndRefsgetLevelAndRefs(Level level, AppenderRef[] refs, java.lang.String levelAndRefs, Configuration config)LogEventFactorygetLogEventFactory()Returns the LogEventFactory.java.lang.StringgetName()Returns the name of the LoggerConfig.LoggerConfiggetParent()Returns the parent of this LoggerConfig.java.util.Map<Property,java.lang.Boolean>getProperties()Deprecated.usegetPropertyList()insteadprivate java.util.List<Property>getProperties(java.lang.String loggerName, java.lang.String fqcn, Marker marker, Level level, Message data, java.lang.Throwable t)private java.util.List<Property>getPropertiesWithLookups(java.lang.String loggerName, java.lang.String fqcn, Marker marker, Level level, Message data, java.lang.Throwable t, java.util.List<Property> props)java.util.List<Property>getPropertyList()Returns an unmodifiable list with the configuration properties, ornullif thisLoggerConfigdoes not have any configuration properties.ReliabilityStrategygetReliabilityStrategy()Returns the object responsible for ensuring log events are delivered to a working appender, even during or after a reconfiguration.protected booleanhasAppenders()protected static booleanincludeLocation(java.lang.String includeLocationConfigValue)protected static booleanincludeLocation(java.lang.String includeLocationConfigValue, Configuration configuration)booleanisAdditive()Returns the valid of the additive flag.booleanisIncludeLocation()Returns the value of logger configuration attributeincludeLocation, or, if no such attribute was configured,trueif logging is synchronous orfalseif logging is asynchronous.booleanisPropertiesRequireLookup()private java.lang.StackTraceElementlocation(java.lang.String fqcn)voidlog(java.lang.String loggerName, java.lang.String fqcn, java.lang.StackTraceElement location, Marker marker, Level level, Message data, java.lang.Throwable t)Logs an event.voidlog(java.lang.String loggerName, java.lang.String fqcn, Marker marker, Level level, Message data, java.lang.Throwable t)Logs an event.voidlog(LogEvent event)Logs an event.protected voidlog(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate)Logs an event.private voidlogParent(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate)static <B extends LoggerConfig.Builder<B>>
BnewBuilder()private voidprocessLogEvent(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate)voidremoveAppender(java.lang.String name)Removes the Appender with the specific name.booleanrequiresLocation()voidsetAdditive(boolean additive)Sets the additive setting.voidsetLevel(Level level)Sets the logging Level.voidsetLogEventFactory(LogEventFactory logEventFactory)Sets the LogEventFactory.voidsetParent(LoggerConfig parent)Sets the parent of this LoggerConfig.java.lang.StringtoString()-
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 Detail
-
ROOT
public static final java.lang.String ROOT
- See Also:
- Constant Field Values
-
LOG_EVENT_FACTORY
private static LogEventFactory LOG_EVENT_FACTORY
-
appenderRefs
private java.util.List<AppenderRef> appenderRefs
-
appenders
private final AppenderControlArraySet appenders
-
name
private final java.lang.String name
-
logEventFactory
private LogEventFactory logEventFactory
-
level
private Level level
-
additive
private boolean additive
-
includeLocation
private boolean includeLocation
-
parent
private LoggerConfig parent
-
propertiesMap
private java.util.Map<Property,java.lang.Boolean> propertiesMap
-
properties
private final java.util.List<Property> properties
-
propertiesRequireLookup
private final boolean propertiesRequireLookup
-
config
private final Configuration config
-
reliabilityStrategy
private final ReliabilityStrategy reliabilityStrategy
-
-
Constructor Detail
-
LoggerConfig
public LoggerConfig()
Default constructor.
-
LoggerConfig
public LoggerConfig(java.lang.String name, Level level, boolean additive)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(java.lang.String name, java.util.List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation)
-
-
Method Detail
-
newBuilder
@PluginBuilderFactory public static <B extends LoggerConfig.Builder<B>> B newBuilder()
-
containsPropertyRequiringLookup
private static boolean containsPropertyRequiringLookup(Property[] properties)
-
getFilter
public Filter getFilter()
Description copied from class:AbstractFilterableReturns the Filter.- Specified by:
getFilterin interfaceFilterable- Overrides:
getFilterin classAbstractFilterable- Returns:
- the Filter or null.
-
getName
public java.lang.String getName()
Returns the name of the LoggerConfig.- Returns:
- the name of the LoggerConfig.
-
setParent
public void setParent(LoggerConfig parent)
Sets the parent of this LoggerConfig.- Parameters:
parent- the parent LoggerConfig.
-
getParent
public LoggerConfig getParent()
Returns the parent of this LoggerConfig.- Returns:
- the LoggerConfig that is the parent of this one.
-
addAppender
public void addAppender(Appender appender, Level level, Filter filter)
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
public void removeAppender(java.lang.String name)
Removes the Appender with the specific name.- Parameters:
name- The name of the Appender.
-
getAppenders
public java.util.Map<java.lang.String,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.
-
cleanupFilter
private void cleanupFilter(AppenderControl ctl)
-
getAppenderRefs
public java.util.List<AppenderRef> getAppenderRefs()
Returns the Appender references.- Returns:
- a List of all the Appender names attached to this LoggerConfig.
-
setLevel
public void setLevel(Level level)
Sets the logging Level.- Parameters:
level- The logging Level.
-
getLevel
public Level getLevel()
Returns the logging Level.- Returns:
- the logging Level.
-
getExplicitLevel
public 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
public LogEventFactory getLogEventFactory()
Returns the LogEventFactory.- Returns:
- the LogEventFactory.
-
setLogEventFactory
public void setLogEventFactory(LogEventFactory logEventFactory)
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,trueif logging is synchronous orfalseif logging is asynchronous.- Returns:
- whether location should be passed downstream
-
getProperties
@Deprecated public java.util.Map<Property,java.lang.Boolean> getProperties()
Deprecated.usegetPropertyList()insteadReturns an unmodifiable map with the configuration properties, ornullif thisLoggerConfigdoes not have any configuration properties.For each
Propertykey in the map, the value istrueif the property value has a variable that needs to be substituted.- Returns:
- an unmodifiable map with the configuration properties, or
null - See Also:
Configuration.getStrSubstitutor(),StrSubstitutor
-
getPropertyList
public java.util.List<Property> getPropertyList()
Returns an unmodifiable list with the configuration properties, ornullif thisLoggerConfigdoes not have any configuration properties.Each
Propertyin the list has an attributevalueNeedsLookupthat istrueif 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:
Configuration.getStrSubstitutor(),StrSubstitutor
-
isPropertiesRequireLookup
public boolean isPropertiesRequireLookup()
-
log
public void log(java.lang.String loggerName, java.lang.String fqcn, Marker marker, Level level, Message data, java.lang.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.
-
location
private java.lang.StackTraceElement location(java.lang.String fqcn)
-
log
public void log(java.lang.String loggerName, java.lang.String fqcn, java.lang.StackTraceElement location, Marker marker, Level level, Message data, java.lang.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.
-
getProperties
private java.util.List<Property> getProperties(java.lang.String loggerName, java.lang.String fqcn, Marker marker, Level level, Message data, java.lang.Throwable t)
-
getPropertiesWithLookups
private java.util.List<Property> getPropertiesWithLookups(java.lang.String loggerName, java.lang.String fqcn, Marker marker, Level level, Message data, java.lang.Throwable t, java.util.List<Property> props)
-
log
public void log(LogEvent event)
Logs an event.- Parameters:
event- The log event.
-
log
protected void log(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate)
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
public ReliabilityStrategy 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
private void processLogEvent(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate)
-
requiresLocation
public boolean requiresLocation()
- Specified by:
requiresLocationin interfaceLocationAware
-
logParent
private void logParent(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate)
-
callAppenders
protected void callAppenders(LogEvent event)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
createLogger
@Deprecated public static LoggerConfig createLogger(java.lang.String additivity, Level level, @PluginAttribute("name") java.lang.String loggerName, java.lang.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") java.lang.String loggerName, @PluginAttribute("includeLocation") java.lang.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
protected static boolean includeLocation(java.lang.String includeLocationConfigValue)
-
includeLocation
protected static boolean includeLocation(java.lang.String includeLocationConfigValue, Configuration configuration)
-
hasAppenders
protected final boolean hasAppenders()
-
getLevelAndRefs
protected static LoggerConfig.LevelAndRefs getLevelAndRefs(Level level, AppenderRef[] refs, java.lang.String levelAndRefs, Configuration config)
-
-