Class Logger
- java.lang.Object
-
- org.apache.log4j.Category
-
- org.apache.log4j.Logger
-
- All Implemented Interfaces:
org.apache.log4j.spi.AppenderAttachable,PaxLoggingManagerAwareLogger
public class Logger extends Category
This is the central class in the log4j package. Most logging operations, except configuration, are done through this class. pax-logging-api has to treat this class both as a factory and as logger itself - with all the configuration-related consequences.- Since:
- log4j 1.2
- Author:
- Ceki Gülcü
-
-
Field Summary
-
Fields inherited from class org.apache.log4j.Category
additive, level, LOG4J_FQCN, m_delegate, m_paxLogging, name, parent, repository
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertLog(boolean assertion, String msg)voiddebug(Object message)Log a message object with theDEBUGlevel.voiddebug(Object messagePattern, Object arg)Log a message with theDEBUGlevel with message formatting done according to the value ofmessagePatternandargparameters.voiddebug(Object message, Throwable t)Log a message object with theDEBUGlevel including the stack trace of theThrowabletpassed as parameter.voiddebug(String messagePattern, Object arg1, Object arg2)Log a message with theDEBUGlevel with message formatting done according to the messagePattern and the arguments arg1 and arg2.voiderror(Object message)Log a message object with theERRORLevel.voiderror(Object messagePattern, Object arg)Log a message with theERRORlevel with message formatting done according to the value ofmessagePatternandargparameters.voiderror(Object message, Throwable t)Log a message object with theERRORlevel including the stack trace of theThrowabletpassed as parameter.voiderror(String messagePattern, Object arg1, Object arg2)Log a message with theERRORlevel with message formatting done according to the messagePattern and the arguments arg1 and arg2.voidfatal(Object message)Log a message object with theFATALLevel.voidfatal(Object messagePattern, Object arg)Log a message with theFATALlevel with message formatting done according to the value ofmessagePatternandargparameters.voidfatal(Object message, Throwable t)Log a message object with theFATALlevel including the stack trace of theThrowabletpassed as parameter.voidfatal(String messagePattern, Object arg1, Object arg2)Log a message with theFATALlevel with message formatting done according to the messagePattern and the arguments arg1 and arg2.static LoggergetLogger(Class clazz)Shorthand forgetLogger(clazz.getName()).static LoggergetLogger(String name)Retrieve a logger named according to the value of thenameparameter.static LoggergetLogger(String name, org.apache.log4j.spi.LoggerFactory factory)LikegetLogger(String)except that the type of logger instantiated depends on the type returned by theLoggerFactory.makeNewLoggerInstance(java.lang.String)method of thefactoryparameter.static LoggergetRootLogger()Return the root logger for the current logger repository.voidinfo(Object message)Log a message object with theINFOLevel.voidinfo(Object messagePattern, Object arg)Log a message with theINFOlevel with message formatting done according to the value ofmessagePatternandargparameters.voidinfo(Object message, Throwable t)Log a message object with theINFOlevel including the stack trace of theThrowabletpassed as parameter.voidinfo(String messagePattern, Object arg1, Object arg2)Log a message with theINFOlevel with message formatting done according to the messagePattern and the arguments arg1 and arg2.booleanisTraceEnabled()Check whether this category is enabled for the TRACE Level.voidlog(String callerFQCN, Priority level, Object message, Throwable t)This is the most generic printing method.voidlog(Priority priority, Object message)This generic form is intended to be used by wrappers.voidlog(Priority priority, Object message, Throwable t)This generic form is intended to be used by wrappers.voidtrace(Object message)Log a message object with theTRACElevel.voidtrace(Object messagePattern, Object arg)Log a message with theTRACElevel with message formatting done according to the value ofmessagePatternandargparameters.voidtrace(Object message, Throwable t)Log a message object with theTRACElevel including the stack trace of theThrowabletpassed as parameter.voidtrace(String messagePattern, Object arg1, Object arg2)Log a message with theTRACElevel with message formatting done according to the messagePattern and the arguments arg1 and arg2.voidwarn(Object message)Log a message object with theWARNLevel.voidwarn(Object messagePattern, Object arg)Log a message with theWARNlevel with message formatting done according to the value ofmessagePatternandargparameters.voidwarn(Object message, Throwable t)voidwarn(String messagePattern, Object arg1, Object arg2)Log a message with theWARNlevel with message formatting done according to the messagePattern and the arguments arg1 and arg2.-
Methods inherited from class org.apache.log4j.Category
addAppender, callAppenders, configurePaxLoggingManager, exists, forcedLog, getAdditivity, getAllAppenders, getAppender, getChainedPriority, getCurrentCategories, getDefaultHierarchy, getEffectiveLevel, getHierarchy, getInstance, getInstance, getLevel, getLoggerRepository, getName, getParent, getPriority, getResourceBundle, getResourceBundleString, getRoot, isAttached, isDebugEnabled, isEnabledFor, isErrorEnabled, isInfoEnabled, isWarnEnabled, l7dlog, l7dlog, removeAllAppenders, removeAppender, removeAppender, setAdditivity, setLevel, setPaxLoggingManager, setPriority, setResourceBundle, shutdown
-
-
-
-
Method Detail
-
getLogger
public static Logger getLogger(String name)
Retrieve a logger named according to the value of thenameparameter. 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.
In pax-logging, loggers are obtained from current or fallback
PaxLoggingManager- Parameters:
name- The name of the logger to retrieve.
-
getLogger
public static Logger getLogger(Class clazz)
Shorthand forgetLogger(clazz.getName()).- Parameters:
clazz- The name ofclazzwill be used as the name of the logger to retrieve. SeegetLogger(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 string value: "root". However, callingLogger.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(String name, org.apache.log4j.spi.LoggerFactory factory)
LikegetLogger(String)except that the type of logger instantiated depends on the type returned by theLoggerFactory.makeNewLoggerInstance(java.lang.String)method of thefactoryparameter.This method is intended to be used by sub-classes.
- Parameters:
name- The name of the logger to retrieve.factory- ALoggerFactoryimplementation that will actually create a new Instance.- Since:
- 0.8.5
-
trace
public void trace(Object message)
Log a message object with theTRACElevel.- Overrides:
tracein classCategory- Parameters:
message- the message object to log.- Since:
- 1.2.12
- See Also:
for an explanation of the logic applied.
-
trace
public void trace(Object message, Throwable t)
Log a message object with theTRACElevel including the stack trace of theThrowabletpassed as parameter.See
debug(Object)form for more detailed information.
-
trace
public void trace(Object messagePattern, Object arg)
Description copied from class:CategoryLog a message with theTRACElevel with message formatting done according to the value ofmessagePatternandargparameters.This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.
-
trace
public void trace(String messagePattern, Object arg1, Object arg2)
Description copied from class:CategoryLog a message with theTRACElevel 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.
-
isTraceEnabled
public boolean isTraceEnabled()
Check whether this category is enabled for the TRACE Level.- Overrides:
isTraceEnabledin classCategory- Returns:
- boolean -
trueif this category is enabled for level TRACE,falseotherwise. - Since:
- 1.2.12
-
debug
public void debug(Object message)
Description copied from class:CategoryLog a message object with theDEBUGlevel.This method first checks if this category is
DEBUGenabled by comparing the level of this category with theDEBUGlevel. If this category isDEBUGenabled, then it converts the message object (passed as parameter) to a string by invoking the appropriateObjectRenderer. It then proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.WARNING Note that passing a
Throwableto this method will print the name of theThrowablebut no stack trace. To print a stack trace use theCategory.debug(Object, Throwable)form instead.
-
debug
public void debug(Object message, Throwable t)
Description copied from class:CategoryLog a message object with theDEBUGlevel including the stack trace of theThrowabletpassed as parameter.See
Category.debug(Object)form for more detailed information.
-
debug
public void debug(Object messagePattern, Object arg)
Description copied from class:CategoryLog a message with theDEBUGlevel with message formatting done according to the value ofmessagePatternandargparameters.This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.
-
debug
public void debug(String messagePattern, Object arg1, Object arg2)
Description copied from class:CategoryLog a message with theDEBUGlevel 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.
-
error
public void error(Object message)
Description copied from class:CategoryLog a message object with theERRORLevel.This method first checks if this category is
ERRORenabled by comparing the level of this category withERRORLevel. If this category isERRORenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.WARNING Note that passing a
Throwableto this method will print the name of theThrowablebut no stack trace. To print a stack trace use theCategory.error(Object, Throwable)form instead.
-
error
public void error(Object message, Throwable t)
Description copied from class:CategoryLog a message object with theERRORlevel including the stack trace of theThrowabletpassed as parameter.See
Category.error(Object)form for more detailed information.
-
error
public void error(Object messagePattern, Object arg)
Description copied from class:CategoryLog a message with theERRORlevel with message formatting done according to the value ofmessagePatternandargparameters.This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.
-
error
public void error(String messagePattern, Object arg1, Object arg2)
Description copied from class:CategoryLog a message with theERRORlevel 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.
-
fatal
public void fatal(Object message)
Description copied from class:CategoryLog a message object with theFATALLevel.This method first checks if this category is
FATALenabled by comparing the level of this category withFATALLevel. If the category isFATALenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.WARNING Note that passing a
Throwableto this method will print the name of the Throwable but no stack trace. To print a stack trace use theCategory.fatal(Object, Throwable)form instead.
-
fatal
public void fatal(Object message, Throwable t)
Description copied from class:CategoryLog a message object with theFATALlevel including the stack trace of theThrowabletpassed as parameter.See
Category.fatal(Object)for more detailed information.
-
fatal
public void fatal(Object messagePattern, Object arg)
Description copied from class:CategoryLog a message with theFATALlevel with message formatting done according to the value ofmessagePatternandargparameters.This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.
-
fatal
public void fatal(String messagePattern, Object arg1, Object arg2)
Description copied from class:CategoryLog a message with theFATALlevel 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.
-
info
public void info(Object message)
Description copied from class:CategoryLog a message object with theINFOLevel.This method first checks if this category is
INFOenabled by comparing the level of this category withINFOLevel. If the category isINFOenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.WARNING Note that passing a
Throwableto this method will print the name of the Throwable but no stack trace. To print a stack trace use theCategory.info(Object, Throwable)form instead.
-
info
public void info(Object message, Throwable t)
Description copied from class:CategoryLog a message object with theINFOlevel including the stack trace of theThrowabletpassed as parameter.See
Category.info(Object)for more detailed information.
-
info
public void info(Object messagePattern, Object arg)
Description copied from class:CategoryLog a message with theINFOlevel with message formatting done according to the value ofmessagePatternandargparameters.This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.
-
info
public void info(String messagePattern, Object arg1, Object arg2)
Description copied from class:CategoryLog a message with theINFOlevel 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.
-
warn
public void warn(Object message)
Description copied from class:CategoryLog a message object with theWARNLevel.This method first checks if this category is
WARNenabled by comparing the level of this category withWARNLevel. If the category isWARNenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hieararchy depending on the value of the additivity flag.WARNING Note that passing a
Throwableto this method will print the name of the Throwable but no stack trace. To print a stack trace use theCategory.warn(Object, Throwable)form instead.
-
warn
public void warn(Object message, Throwable t)
Description copied from class:CategoryLog a message with theWARNlevel including the stack trace of theThrowabletpassed as parameter.See
Category.warn(Object)for more detailed information.
-
warn
public void warn(Object messagePattern, Object arg)
Description copied from class:CategoryLog a message with theWARNlevel with message formatting done according to the value ofmessagePatternandargparameters.This form avoids superflous parameter construction. Whenever possible, you should use this form instead of constructing the message parameter using string concatenation.
-
warn
public void warn(String messagePattern, Object arg1, Object arg2)
Description copied from class:CategoryLog a message with theWARNlevel 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.
-
assertLog
public void assertLog(boolean assertion, String msg)Description copied from class:CategoryIfassertionparameter isfalse, then logsmsgas anerrorstatement.The
assertmethod has been renamed toassertLogbecauseassertis a language reserved word in JDK 1.4.
-
log
public void log(Priority priority, Object message, Throwable t)
Description copied from class:CategoryThis generic form is intended to be used by wrappers.
-
log
public void log(Priority priority, Object message)
Description copied from class:CategoryThis generic form is intended to be used by wrappers.
-
-