Log4j 1.3alpha-1

org.apache.log4j
Class Logger

java.lang.Object
  |
  +--org.apache.log4j.Category
        |
        +--org.apache.log4j.Logger
All Implemented Interfaces:
AppenderAttachable
Direct Known Subclasses:
RootCategory, RootLogger

public class Logger
extends Category

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, lock, name, parent, repository, resourceBundle
 
Constructor Summary
protected Logger(java.lang.String name)
          This constructor creates a new Logger instance and sets its name.
 
Method Summary
 void debug(java.lang.String messagePattern, java.lang.Object arg1, java.lang.Object arg2)
          Log a message with the DEBUG level with message formatting done according to the messagePattern and the arguments arg1 and arg2.
 void error(java.lang.String messagePattern, java.lang.Object arg1, java.lang.Object arg2)
          Log a message with the ERROR level with message formatting done according to the messagePattern and the arguments arg1 and arg2.
 void fatal(java.lang.String messagePattern, java.lang.Object arg1, java.lang.Object arg2)
          Log a message with the FATAL level with message formatting done according to the messagePattern and the arguments arg1 and arg2.
static Logger getLogger(java.lang.Class clazz)
          Shorthand for getLogger(clazz.getName()).
static Logger getLogger(java.lang.String name)
          Retrieve a logger by name.
static Logger getLogger(java.lang.String name, 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 of logger for the current hierarchy.
 void info(java.lang.String messagePattern, java.lang.Object arg1, java.lang.Object arg2)
          Log a message with the INFO level with message formatting done according to the messagePattern and the arguments arg1 and arg2.
 void trace(java.lang.Object message)
          Log a message object with the TRACE level.
 void trace(java.lang.Object messagePattern, java.lang.Object arg)
          Log a message with the TRACE level with message formatting done according to the value of messagePattern and arg parameters.
 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 messagePattern, java.lang.Object arg1, java.lang.Object arg2)
          Log a message with the TRACE level with message formatting done according to the messagePattern and the arguments arg1 and arg2.
 void warn(java.lang.String messagePattern, java.lang.Object arg1, java.lang.Object arg2)
          Log a message with the WARN level with message formatting done according to the messagePattern and the arguments arg1 and arg2.
 
Methods inherited from class org.apache.log4j.Category
addAppender, assertLog, callAppenders, debug, debug, debug, error, error, error, exists, fatal, fatal, fatal, forcedLog, getAdditivity, getAllAppenders, getAppender, getChainedPriority, getCurrentCategories, getDefaultHierarchy, getEffectiveLevel, getHierarchy, getInstance, getInstance, getLevel, getLoggerRepository, getName, getParent, getPriority, getResourceBundle, getResourceBundleString, getRoot, info, info, info, isAttached, isDebugEnabled, isEnabledFor, isEnabledFor, isInfoEnabled, isTraceEnabled, l7dlog, l7dlog, log, log, log, log, log, log, removeAllAppenders, removeAppender, removeAppender, setAdditivity, setLevel, setResourceBundle, shutdown, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Logger

protected Logger(java.lang.String name)
This constructor creates a new Logger instance and sets its name.

It is intended to be used by sub-classes only. You should not create loggers directly.

Parameters:
name - The name of the logger.
Method Detail

getLogger

public static Logger getLogger(java.lang.String name)
Retrieve a logger by name. If the named logger already exists, then the existing instance will be reutrned. Otherwise, a new instance is created.

By default, loggers do not have a set level but inherit it from their ancestors. 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 of logger for the current hierarchy.

The root logger is always instantiated and available. It's name is "root".

Nevertheless, note that calling Logger.getLogger("root") does not retrieve the root logger but a logger just under root named "root".


getLogger

public static Logger getLogger(java.lang.String name,
                               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.3
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.

trace

public void trace(java.lang.Object messagePattern,
                  java.lang.Object arg)
Log a message with the TRACE level with message formatting done according to the value of messagePattern and arg parameters.

This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

Parameters:
messagePattern - The message pattern which will be parsed and formatted
arg - The argument to replace the formatting element, i,e, the '{}' pair within messagePattern.
Since:
1.3

trace

public void trace(java.lang.String messagePattern,
                  java.lang.Object arg1,
                  java.lang.Object arg2)
Log a message with the TRACE level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

Parameters:
messagePattern - The message pattern which will be parsed and formatted
arg1 - The first argument to replace the first formatting element
arg2 - The second argument to replace the second formatting element
Since:
1.3

debug

public void debug(java.lang.String messagePattern,
                  java.lang.Object arg1,
                  java.lang.Object arg2)
Log a message with the DEBUG level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

Parameters:
messagePattern - The message pattern which will be parsed and formatted
arg1 - The first argument to replace the first formatting element
arg2 - The second argument to replace the second formatting element
Since:
1.3

info

public void info(java.lang.String messagePattern,
                 java.lang.Object arg1,
                 java.lang.Object arg2)
Log a message with the INFO level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

Parameters:
messagePattern - The message pattern which will be parsed and formatted
arg1 - The first argument to replace the first formatting element
arg2 - The second argument to replace the second formatting element
Since:
1.3

warn

public void warn(java.lang.String messagePattern,
                 java.lang.Object arg1,
                 java.lang.Object arg2)
Log a message with the WARN level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

Parameters:
messagePattern - The message pattern which will be parsed and formatted
arg1 - The first argument to replace the first formatting element
arg2 - The second argument to replace the second formatting element
Since:
1.3

error

public void error(java.lang.String messagePattern,
                  java.lang.Object arg1,
                  java.lang.Object arg2)
Log a message with the ERROR level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

Parameters:
messagePattern - The message pattern which will be parsed and formatted
arg1 - The first argument to replace the first formatting element
arg2 - The second argument to replace the second formatting element
Since:
1.3

fatal

public void fatal(java.lang.String messagePattern,
                  java.lang.Object arg1,
                  java.lang.Object arg2)
Log a message with the FATAL level with message formatting done according to the messagePattern and the arguments arg1 and arg2.

This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.

Parameters:
messagePattern - The message pattern which will be parsed and formatted
arg1 - The first argument to replace the first formatting element
arg2 - The second argument to replace the second formatting element
Since:
1.3

Log4j 1.3alpha-1

Copyright 2000-2003 Apache Software Foundation.