org.apache.log4j
Class Logger

java.lang.Object
  extended byorg.apache.log4j.Category
      extended byorg.apache.log4j.Logger
All Implemented Interfaces:
org.apache.log4j.spi.AppenderAttachable, Loggable
Direct Known Subclasses:
Log4jLogger

public class Logger
extends org.apache.log4j.Category
implements Loggable

This is the central class in the log4j package. Most logging operations, except configuration, are done through this class.

Since:
log4j 1.2
Author:
Ceki Gülcü

Field Summary
 
Fields inherited from class org.apache.log4j.Category
additive, level, name, parent, repository, resourceBundle
 
Constructor Summary
protected Logger(java.lang.String name)
           
 
Method Summary
 void debug(java.lang.String message)
          Writes a debug message.
 void error(java.lang.String message)
          Writes a error message.
 void fatal(java.lang.String message)
          Writes a fatal message.
static Logger getLogger(java.lang.Class clazz)
          Shorthand for getLogger(clazz.getName()).
static Logger getLogger(java.lang.String name)
          Retrieve a logger named according to the value of the name parameter.
static Logger getLogger(java.lang.String name, org.apache.log4j.spi.LoggerFactory factory)
          Like getLogger(String) except that the type of logger instantiated depends on the type returned by the LoggerFactory.makeNewLoggerInstance(java.lang.String) method of the factory parameter.
static Logger getRootLogger()
          Return the root logger for the current logger repository.
 void info(java.lang.String message)
          Writes an info message.
 boolean isErrorEnabled()
          Determines if error is enabled.
 boolean isFatalEnabled()
          Determines if fatal is enabled.
 boolean isTraceEnabled()
          Check whether this category is enabled for the TRACE Level.
 boolean isWarnEnabled()
          Determines if warn is enabled.
 void trace(java.lang.Object message)
          Log a message object with the TRACE level.
 void trace(java.lang.Object message, java.lang.Throwable t)
          Log a message object with the TRACE level including the stack trace of the Throwablet passed as parameter.
 void trace(java.lang.String message)
          Writes a trace message.
 void warn(java.lang.String message)
          Writes a warning message.
 
Methods inherited from class org.apache.log4j.Category
addAppender, assertLog, callAppenders, debug, debug, error, error, exists, fatal, fatal, forcedLog, getAdditivity, getAllAppenders, getAppender, getChainedPriority, getCurrentCategories, getDefaultHierarchy, getEffectiveLevel, getHierarchy, getInstance, getInstance, getLevel, getLoggerRepository, getName, getParent, getPriority, getResourceBundle, getResourceBundleString, getRoot, info, info, isAttached, isDebugEnabled, isEnabledFor, isInfoEnabled, l7dlog, l7dlog, log, log, log, removeAllAppenders, removeAppender, removeAppender, setAdditivity, setLevel, setPriority, setResourceBundle, shutdown, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.jagacy.util.Loggable
isDebugEnabled, isInfoEnabled
 

Constructor Detail

Logger

protected Logger(java.lang.String name)
Method Detail

getLogger

public static Logger getLogger(java.lang.String name)
Retrieve a logger named according to the value of the name parameter. If the named logger already exists, then the existing instance will be returned. Otherwise, a new instance is created.

By default, loggers do not have a set level but inherit it from their neareast ancestor with a set level. This is one of the central features of log4j.

Parameters:
name - The name of the logger to retrieve.

getLogger

public static Logger getLogger(java.lang.Class clazz)
Shorthand for getLogger(clazz.getName()).

Parameters:
clazz - The name of clazz will be used as the name of the logger to retrieve. See getLogger(String) for more detailed information.

getRootLogger

public static Logger getRootLogger()
Return the root logger for the current logger repository.

The Logger.getName() method for the root logger always returns stirng value: "root". However, calling Logger.getLogger("root") does not retrieve the root logger but a logger just under root named "root".

In other words, calling this method is the only way to retrieve the root logger.


getLogger

public static Logger getLogger(java.lang.String name,
                               org.apache.log4j.spi.LoggerFactory factory)
Like getLogger(String) except that the type of logger instantiated depends on the type returned by the LoggerFactory.makeNewLoggerInstance(java.lang.String) method of the factory parameter.

This method is intended to be used by sub-classes.

Parameters:
name - The name of the logger to retrieve.
factory - A LoggerFactory implementation that will actually create a new Instance.
Since:
0.8.5

trace

public void trace(java.lang.Object message)
Log a message object with the TRACE level.

Parameters:
message - the message object to log.
Since:
1.2.12
See Also:
for an explanation of the logic applied.

trace

public void trace(java.lang.Object message,
                  java.lang.Throwable t)
Log a message object with the TRACE level including the stack trace of the Throwablet passed as parameter.

See Category.debug(Object) form for more detailed information.

Parameters:
message - the message object to log.
t - the exception to log, including its stack trace.
Since:
1.2.12

isTraceEnabled

public boolean isTraceEnabled()
Check whether this category is enabled for the TRACE Level.

Specified by:
isTraceEnabled in interface Loggable
Returns:
boolean - true if this category is enabled for level TRACE, false otherwise.
Since:
1.2.12

debug

public void debug(java.lang.String message)
Description copied from interface: Loggable
Writes a debug message.

Specified by:
debug in interface Loggable
Parameters:
message - Message to write.

error

public void error(java.lang.String message)
Description copied from interface: Loggable
Writes a error message.

Specified by:
error in interface Loggable
Parameters:
message - Message to write.

fatal

public void fatal(java.lang.String message)
Description copied from interface: Loggable
Writes a fatal message.

Specified by:
fatal in interface Loggable
Parameters:
message - Message to write.

info

public void info(java.lang.String message)
Description copied from interface: Loggable
Writes an info message.

Specified by:
info in interface Loggable
Parameters:
message - Message to write.

isErrorEnabled

public boolean isErrorEnabled()
Description copied from interface: Loggable
Determines if error is enabled.

Specified by:
isErrorEnabled in interface Loggable
Returns:
true if its enabled; false otherwise.

isFatalEnabled

public boolean isFatalEnabled()
Description copied from interface: Loggable
Determines if fatal is enabled.

Specified by:
isFatalEnabled in interface Loggable
Returns:
true if its enabled; false otherwise.

isWarnEnabled

public boolean isWarnEnabled()
Description copied from interface: Loggable
Determines if warn is enabled.

Specified by:
isWarnEnabled in interface Loggable
Returns:
true if its enabled; false otherwise.

trace

public void trace(java.lang.String message)
Description copied from interface: Loggable
Writes a trace message.

Specified by:
trace in interface Loggable
Parameters:
message - Message to write.

warn

public void warn(java.lang.String message)
Description copied from interface: Loggable
Writes a warning message.

Specified by:
warn in interface Loggable
Parameters:
message - Message to write.