org.apache.logging.log4j.core
Class Logger

java.lang.Object
  extended by org.apache.logging.log4j.spi.AbstractLogger
      extended by org.apache.logging.log4j.core.Logger
All Implemented Interfaces:
Serializable, org.apache.logging.log4j.Logger, org.apache.logging.log4j.spi.ExtendedLogger
Direct Known Subclasses:
AsyncLogger

public class Logger
extends org.apache.logging.log4j.spi.AbstractLogger

See Also:
Serialized Form
Troublesome:
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.

Nested Class Summary
protected  class Logger.PrivateConfig
          The binding between a Logger and its configuration.
 
Field Summary
protected  Logger.PrivateConfig config
          config should be consistent across threads.
 
Fields inherited from class org.apache.logging.log4j.spi.AbstractLogger
CATCHING_MARKER, DEFAULT_MESSAGE_FACTORY_CLASS, ENTRY_MARKER, EXCEPTION_MARKER, EXIT_MARKER, FLOW_MARKER, THROWING_MARKER
 
Constructor Summary
protected Logger(LoggerContext context, String name, org.apache.logging.log4j.message.MessageFactory messageFactory)
          The constructor.
 
Method Summary
 void addAppender(Appender appender)
          This method is not exposed through the public API and is used primarily for unit testing.
 void addFilter(Filter filter)
          This method is not exposed through the public API and is used primarily for unit testing.
 int filterCount()
          This method is not exposed through the public API and is used primarily for unit testing.
 Map<String,Appender> getAppenders()
          This method is not exposed through the public API and is used primarily for unit testing.
 LoggerContext getContext()
          Returns the LoggerContext this Logger is associated with.
 Iterator<Filter> getFilters()
          This method is not exposed through the public API and is used primarily for unit testing.
 org.apache.logging.log4j.Level getLevel()
          Gets the Level associated with the Logger.
 Logger getParent()
          This method is only used for 1.x compatibility.
 boolean isAdditive()
          This method is not exposed through the public API and is present only to support the Log4j 1.2 compatibility bridge.
 boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, org.apache.logging.log4j.message.Message message, Throwable t)
           
 boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, Object message, Throwable t)
           
 boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message)
           
 boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Object... params)
           
 boolean isEnabled(org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String message, Throwable t)
           
 void logMessage(String fqcn, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, org.apache.logging.log4j.message.Message message, Throwable t)
           
 void removeAppender(Appender appender)
          This method is not exposed through the public API and is used primarily for unit testing.
 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.
 void setLevel(org.apache.logging.log4j.Level level)
          This method is not exposed through the public API and is provided primarily for unit testing.
 String toString()
          Returns a String representation of this instance in the form "name:level[ in context_name]".
 
Methods inherited from class org.apache.logging.log4j.spi.AbstractLogger
catching, catching, catching, catchingMsg, checkMessageFactory, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, entry, entry, entry, entryMsg, error, error, error, error, error, error, error, error, error, error, error, error, error, error, exit, exit, exit, exitMsg, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, getMessageFactory, getName, info, info, info, info, info, info, info, info, info, info, info, info, info, info, isDebugEnabled, isDebugEnabled, isEnabled, 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, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logMessage, logMessage, logMessage, logMessage, printf, printf, throwing, throwing, throwing, throwingMsg, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

config

protected volatile Logger.PrivateConfig config
config should be consistent across threads.

Constructor Detail

Logger

protected Logger(LoggerContext context,
                 String name,
                 org.apache.logging.log4j.message.MessageFactory messageFactory)
The constructor.

Parameters:
context - The LoggerContext this Logger is associated with.
messageFactory - The message factory.
name - The name of the Logger.
Method Detail

getParent

public Logger 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

public LoggerContext 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.

Parameters:
level - The Level to use on this Logger.

logMessage

public void logMessage(String fqcn,
                       org.apache.logging.log4j.Level level,
                       org.apache.logging.log4j.Marker marker,
                       org.apache.logging.log4j.message.Message message,
                       Throwable t)

isEnabled

public boolean isEnabled(org.apache.logging.log4j.Level level,
                         org.apache.logging.log4j.Marker marker,
                         String message,
                         Throwable t)

isEnabled

public boolean isEnabled(org.apache.logging.log4j.Level level,
                         org.apache.logging.log4j.Marker marker,
                         String message)

isEnabled

public boolean isEnabled(org.apache.logging.log4j.Level level,
                         org.apache.logging.log4j.Marker marker,
                         String message,
                         Object... params)

isEnabled

public boolean isEnabled(org.apache.logging.log4j.Level level,
                         org.apache.logging.log4j.Marker marker,
                         Object message,
                         Throwable t)

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)

addAppender

public void addAppender(Appender appender)
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

public void removeAppender(Appender appender)
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

public Map<String,Appender> 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

public Iterator<Filter> 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.

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

public void addFilter(Filter filter)
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.

toString

public String toString()
Returns a String representation of this instance in the form "name:level[ in context_name]".

Overrides:
toString in class Object
Returns:
A String describing this Logger instance.


Copyright © 1999-2014 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.