Class Logger

All Implemented Interfaces:
Serializable, Supplier<LoggerConfig>, Logger, ExtendedLogger, LocationAwareLogger, Supplier<LoggerConfig>
Direct Known Subclasses:
AsyncLogger

public class Logger extends AbstractLogger implements 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. TODO All the isEnabled methods could be pushed into a filter interface. Not sure of the utility of having isEnabled be able to examine the message pattern and parameters. (RG) Moving the isEnabled methods out of Logger noticeably impacts performance. The message pattern and parameters are required so that they can be used in global filters.
See Also:
  • Field Details

    • privateConfig

      protected volatile Logger.PrivateConfig privateConfig
      Config should be consistent across threads.
  • Constructor Details

    • Logger

      protected Logger(LoggerContext context, String name, MessageFactory messageFactory)
      Constructs an instance using the given LoggerContext, logger name, and MessageFactory.
      Parameters:
      context - the LoggerContext this logger is associated with
      messageFactory - The message factory to be used. If null, first the "log4j2.messageFactory" property will be used to instantiate the message factory. If the property is missing and the log4j2.enableThreadLocals property is not false, ReusableMessageFactory will be used. Otherwise, we will fall back to ParameterizedMessageFactory.
      name - the logger name
    • Logger

      protected Logger(LoggerContext context, String name, MessageFactory messageFactory, FlowMessageFactory flowMessageFactory)
      The canonical constructor.
      Parameters:
      context - the LoggerContext this logger is associated with
      messageFactory - The message factory to be used. If null, first the "log4j2.messageFactory" property will be used to instantiate the message factory. If the property is missing and the log4j2.enableThreadLocals property is not false, ReusableMessageFactory will be used. Otherwise, we will fall back to ParameterizedMessageFactory.
      flowMessageFactory - The flow message factory to be used. If null, first the "log4j2.flowMessageFactory" property will be used to instantiate the flow message factory. If the property is missing, DefaultFlowMessageFactory will be used.
      name - the logger name
  • Method Details