Package org.apache.logging.log4j.core
Class Logger
java.lang.Object
org.apache.logging.log4j.kit.logger.AbstractLogger
org.apache.logging.log4j.core.Logger
- All Implemented Interfaces:
Supplier<LoggerConfig>,org.apache.logging.log4j.Logger,org.apache.logging.log4j.spi.ExtendedLogger,org.apache.logging.log4j.util.Supplier<LoggerConfig>
@NullMarked
public class Logger
extends AbstractLogger
implements org.apache.logging.log4j.util.Supplier<LoggerConfig>
The core implementation of the
Logger interface. Besides providing an implementation
of all the Logger methods, this class also provides some convenience methods for Log4j 1.x compatibility as well as
access to the Filters and Appenders associated with this Logger. Note that access to these underlying objects is provided primarily for use in
unit tests or bridging legacy Log4j 1.x code. Future versions of this class may or may not include the various
methods that are noted as not being part of the public API.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprotected classThe binding between a Logger and its configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Logger.PrivateConfigConfig should be consistent across threads.Fields inherited from class org.apache.logging.log4j.kit.logger.AbstractLogger
CATCHING_MARKER, ENTRY_MARKER, EXCEPTION_MARKER, EXIT_MARKER, FLOW_MARKER, THROWING_MARKER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLogger(LoggerContext context, String name, org.apache.logging.log4j.message.MessageFactory messageFactory, org.apache.logging.log4j.message.FlowMessageFactory flowMessageFactory, RecyclerFactory recyclerFactory, org.apache.logging.log4j.Logger statusLogger) The constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAppender(Appender appender) This method is not exposed through the public API and is used primarily for unit testing.voidThis method is not exposed through the public API and is used primarily for unit testing.org.apache.logging.log4j.LogBuilderatLevel(org.apache.logging.log4j.Level level) protected voiddoLog(String fqcn, @Nullable StackTraceElement location, org.apache.logging.log4j.Level level, @Nullable org.apache.logging.log4j.Marker marker, @Nullable org.apache.logging.log4j.message.Message message, @Nullable Throwable throwable) booleanintThis method is not exposed through the public API and is used primarily for unit testing.get()This method is not exposed through the public API and is used primarily for unit testing.Returns the LoggerContext this Logger is associated with.This method is not exposed through the public API and is used primarily for unit testing.org.apache.logging.log4j.LevelgetLevel()Gets the Level associated with the Logger.This method is only used for 1.x compatibility.inthashCode()booleanThis method is not exposed through the public API and is present only to support the Log4j 1.2 compatibility bridge.booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, CharSequence message, Throwable t) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, Object message, Throwable t) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object... params) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Throwable t) booleanisEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, org.apache.logging.log4j.message.Message message, Throwable t) voidremoveAppender(Appender appender) This method is not exposed through the public API and is used primarily for unit testing.protected booleanvoidsetAdditive(boolean additive) This method is not exposed through the public API and is present only to support the Log4j 1.2 compatibility bridge.voidsetLevel(org.apache.logging.log4j.Level level) This method is not exposed through the public API and is provided primarily for unit testing.toString()Returns a String representation of this instance in the form"name:level[ in context_name]".protected voidupdateConfiguration(Configuration newConfig) Associates this Logger with a new Configuration.Methods inherited from class org.apache.logging.log4j.kit.logger.AbstractLogger
always, atDebug, atError, atFatal, atInfo, atTrace, atWarn, catching, catching, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, entry, entry, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, exit, exit, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, getFlowMessageFactory, getLogBuilder, getMessageFactory, getName, getRecursionDepth, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, isDebugEnabled, isDebugEnabled, isEnabled, isErrorEnabled, isErrorEnabled, isFatalEnabled, isFatalEnabled, isInfoEnabled, isInfoEnabled, isTraceEnabled, isTraceEnabled, isWarnEnabled, isWarnEnabled, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, logCatchingMessage, logEnterMessage, logEnterMessage, logExitMessage, logExitMessage, logExitMessage, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logPrintfMessage, logThrowingMessage, printf, printf, throwing, throwing, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, traceEntry, traceEntry, traceEntry, traceEntry, traceEntry, traceExit, traceExit, traceExit, traceExit, traceExit, traceExit, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn
-
Field Details
-
privateConfig
Config should be consistent across threads.
-
-
Constructor Details
-
Logger
protected Logger(LoggerContext context, String name, org.apache.logging.log4j.message.MessageFactory messageFactory, org.apache.logging.log4j.message.FlowMessageFactory flowMessageFactory, RecyclerFactory recyclerFactory, org.apache.logging.log4j.Logger statusLogger) The constructor.- Parameters:
context- The LoggerContext this Logger is associated with.name- The name of the Logger.messageFactory- The message factory to use for logging methods.flowMessageFactory- The flow message factory to use for flow logging methods.recyclerFactory- The recycler to use for log builder instances.
-
-
Method Details
-
getParent
This method is only used for 1.x compatibility. Returns the parent of this Logger. If it doesn't already exist return a temporary Logger.- Returns:
- The parent Logger.
-
getContext
Returns the LoggerContext this Logger is associated with.- Returns:
- the LoggerContext.
-
setLevel
public void setLevel(org.apache.logging.log4j.Level level) This method is not exposed through the public API and is provided primarily for unit testing.If the new level is null, this logger inherits the level from its parent.
- Parameters:
level- The Level to use on this Logger, may be null.
-
get
- Specified by:
getin interfaceSupplier<LoggerConfig>- Specified by:
getin interfaceorg.apache.logging.log4j.util.Supplier<LoggerConfig>
-
requiresLocation
protected boolean requiresLocation() -
doLog
protected void doLog(String fqcn, @Nullable StackTraceElement location, org.apache.logging.log4j.Level level, @Nullable org.apache.logging.log4j.Marker marker, @Nullable org.apache.logging.log4j.message.Message message, @Nullable Throwable throwable) - Specified by:
doLogin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.Logger- Specified by:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Throwable t) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object... params) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, CharSequence message, Throwable t) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, Object message, Throwable t) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
isEnabled
public boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, org.apache.logging.log4j.message.Message message, Throwable t) - Specified by:
isEnabledin interfaceorg.apache.logging.log4j.spi.ExtendedLogger- Overrides:
isEnabledin classAbstractLogger
-
addAppender
This method is not exposed through the public API and is used primarily for unit testing.- Parameters:
appender- The Appender to add to the Logger.
-
removeAppender
This method is not exposed through the public API and is used primarily for unit testing.- Parameters:
appender- The Appender to remove from the Logger.
-
getAppenders
This method is not exposed through the public API and is used primarily for unit testing.- Returns:
- A Map containing the Appender's name as the key and the Appender as the value.
-
getFilters
This method is not exposed through the public API and is used primarily for unit testing.- Returns:
- An Iterator over all the Filters associated with the Logger.
-
getLevel
public org.apache.logging.log4j.Level getLevel()Gets the Level associated with the Logger.- Specified by:
getLevelin interfaceorg.apache.logging.log4j.Logger- Returns:
- the Level associate with the Logger.
-
filterCount
public int filterCount()This method is not exposed through the public API and is used primarily for unit testing.- Returns:
- The number of Filters associated with the Logger.
-
addFilter
This method is not exposed through the public API and is used primarily for unit testing.- Parameters:
filter- The Filter to add.
-
isAdditive
public boolean isAdditive()This method is not exposed through the public API and is present only to support the Log4j 1.2 compatibility bridge.- Returns:
- true if the associated LoggerConfig is additive, false otherwise.
-
setAdditive
public void setAdditive(boolean additive) This method is not exposed through the public API and is present only to support the Log4j 1.2 compatibility bridge.- Parameters:
additive- Boolean value to indicate whether the Logger is additive or not.
-
atLevel
public org.apache.logging.log4j.LogBuilder atLevel(org.apache.logging.log4j.Level level) - Specified by:
atLevelin interfaceorg.apache.logging.log4j.Logger- Overrides:
atLevelin classAbstractLogger
-
updateConfiguration
Associates this Logger with a new Configuration. This method is not exposed through the public API.There are two ways this could be used to guarantee all threads are aware of changes to config.
- Synchronize this method. Accessors don't need to be synchronized as Java will treat all variables within a synchronized block as volatile.
- Declare the variable volatile. Option 2 is used here as the performance cost is very low and it does a better job at documenting how it is used.
- Parameters:
newConfig- The new Configuration.
-
toString
Returns a String representation of this instance in the form"name:level[ in context_name]". -
equals
-
hashCode
public int hashCode()
-