Package org.apache.log4j
Class Logger
- java.lang.Object
-
- org.apache.log4j.Category
-
- org.apache.log4j.Logger
-
- All Implemented Interfaces:
AppenderAttachable
- Direct Known Subclasses:
NOPLogger,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, name, parent, repository, resourceBundle
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLogger(java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LoggergetLogger(java.lang.Class clazz)Shorthand forgetLogger(clazz.getName()).static LoggergetLogger(java.lang.String name)Retrieve a logger named according to the value of thenameparameter.static LoggergetLogger(java.lang.String name, 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.booleanisTraceEnabled()Check whether this category is enabled for the TRACE Level.voidtrace(java.lang.Object message)Log a message object with theTRACElevel.voidtrace(java.lang.Object message, java.lang.Throwable t)Log a message object with theTRACElevel including the stack trace of theThrowabletpassed as parameter.-
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
-
-
-
-
Method Detail
-
getLogger
public static Logger getLogger(java.lang.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.
- Parameters:
name- The name of the logger to retrieve.
-
getLogger
public static Logger getLogger(java.lang.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(java.lang.String name, 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(java.lang.Object message)
Log a message object with theTRACElevel.- 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 theTRACElevel including the stack trace of theThrowabletpassed 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.- Returns:
- boolean -
trueif this category is enabled for level TRACE,falseotherwise. - Since:
- 1.2.12
-
-