Package org.apache.log
Class Logger
- java.lang.Object
-
- org.apache.log.Logger
-
public class Logger extends java.lang.Object
The object interacted with by client objects to perform logging.
-
-
Field Summary
Fields Modifier and Type Field Description static char
CATEGORY_SEPARATOR
Separator character use to separate different categoriesprivate static Logger[]
EMPTY_SET
private boolean
m_additivity
True means LogEvents will be sent to parents LogTargets aswell as the ones set for this Logger.private java.lang.String
m_category
private Logger[]
m_children
private ErrorHandler
m_errorHandler
private LoggerListener
m_loggerListener
private LogTarget[]
m_logTargets
private boolean
m_logTargetsForceSet
private Logger
m_parent
private Priority
m_priority
private boolean
m_priorityForceSet
-
Constructor Summary
Constructors Constructor Description Logger(ErrorHandler errorHandler, LoggerListener loggerListener, java.lang.String category, LogTarget[] logTargets, Logger parent)
Protected constructor for use inside the logging toolkit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
debug(java.lang.String message)
Log a debug priority event.void
debug(java.lang.String message, java.lang.Throwable throwable)
Log a debug priority event.void
error(java.lang.String message)
Log a error priority event.void
error(java.lang.String message, java.lang.Throwable throwable)
Log a error priority event.void
fatalError(java.lang.String message)
Log a fatalError priority event.void
fatalError(java.lang.String message, java.lang.Throwable throwable)
Log a fatalError priority event.private void
fireEvent(LogEvent event, LogTarget[] targets)
Logger
getChildLogger(java.lang.String subCategory)
Create a new child logger.Logger[]
getChildren()
Get all the child Loggers of current logger.void
info(java.lang.String message)
Log a info priority event.void
info(java.lang.String message, java.lang.Throwable throwable)
Log a info priority event.boolean
isDebugEnabled()
Determine if messages of priority DEBUG will be logged.boolean
isErrorEnabled()
Determine if messages of priority ERROR will be logged.boolean
isFatalErrorEnabled()
Determine if messages of priority FATAL_ERROR will be logged.boolean
isInfoEnabled()
Determine if messages of priority INFO will be logged.boolean
isPriorityEnabled(Priority priority)
Determine if messages of priority will be logged.boolean
isWarnEnabled()
Determine if messages of priority WARN will be logged.void
log(Priority priority, java.lang.String message)
Log a event at specific priority with a certain message.void
log(Priority priority, java.lang.String message, java.lang.Throwable throwable)
Log a event at specific priority with a certain message and throwable.private void
output(LogEvent event)
private void
output(Priority priority, java.lang.String message, java.lang.Throwable throwable)
Internal method to do actual outputting.private void
resetChildLogTargets(boolean recursive)
Update logTargets of children if any.private void
resetChildPriorities(boolean recursive)
Update priority of children if any.private void
resetLogTargets(boolean recursive)
Update logTarget of this Logger.private void
resetPriority(boolean recursive)
Update priority of this Logger.private LogTarget[]
safeGetLogTargets()
Retrieve logtarget array contained in logger.void
setAdditivity(boolean additivity)
Make this logger additive.void
setLogTargets(LogTarget[] logTargets)
Set the log targets for this logger.void
setPriority(Priority priority)
Set the priority for this logger.private void
setupErrorHandlers()
Set ErrorHandlers of LogTargets if necessary.void
unsetLogTargets()
Unset the logtargets for this logger.void
unsetLogTargets(boolean recursive)
Unset the logtargets for this logger and all child loggers if recursive is set.void
unsetPriority()
Unset the priority of Logger.void
unsetPriority(boolean recursive)
Unset the priority of Logger.void
warn(java.lang.String message)
Log a warn priority event.void
warn(java.lang.String message, java.lang.Throwable throwable)
Log a warn priority event.
-
-
-
Field Detail
-
EMPTY_SET
private static final Logger[] EMPTY_SET
-
CATEGORY_SEPARATOR
public static final char CATEGORY_SEPARATOR
Separator character use to separate different categories- See Also:
- Constant Field Values
-
m_errorHandler
private final ErrorHandler m_errorHandler
-
m_loggerListener
private final LoggerListener m_loggerListener
-
m_parent
private final Logger m_parent
-
m_category
private final java.lang.String m_category
-
m_children
private Logger[] m_children
-
m_logTargets
private LogTarget[] m_logTargets
-
m_logTargetsForceSet
private boolean m_logTargetsForceSet
-
m_priority
private Priority m_priority
-
m_priorityForceSet
private boolean m_priorityForceSet
-
m_additivity
private boolean m_additivity
True means LogEvents will be sent to parents LogTargets aswell as the ones set for this Logger.
-
-
Constructor Detail
-
Logger
Logger(ErrorHandler errorHandler, LoggerListener loggerListener, java.lang.String category, LogTarget[] logTargets, Logger parent)
Protected constructor for use inside the logging toolkit. You should not be using this constructor directly.- Parameters:
errorHandler
- the ErrorHandler logger uses to log errorscategory
- the fully qualified name of categorylogTargets
- the LogTargets associated with loggerparent
- the parent logger (used for inheriting from)
-
-
Method Detail
-
isDebugEnabled
public final boolean isDebugEnabled()
Determine if messages of priority DEBUG will be logged.- Returns:
- true if DEBUG messages will be logged
-
debug
public final void debug(java.lang.String message, java.lang.Throwable throwable)
Log a debug priority event.- Parameters:
message
- the messagethrowable
- the throwable
-
debug
public final void debug(java.lang.String message)
Log a debug priority event.- Parameters:
message
- the message
-
isInfoEnabled
public final boolean isInfoEnabled()
Determine if messages of priority INFO will be logged.- Returns:
- true if INFO messages will be logged
-
info
public final void info(java.lang.String message, java.lang.Throwable throwable)
Log a info priority event.- Parameters:
message
- the messagethrowable
- the throwable
-
info
public final void info(java.lang.String message)
Log a info priority event.- Parameters:
message
- the message
-
isWarnEnabled
public final boolean isWarnEnabled()
Determine if messages of priority WARN will be logged.- Returns:
- true if WARN messages will be logged
-
warn
public final void warn(java.lang.String message, java.lang.Throwable throwable)
Log a warn priority event.- Parameters:
message
- the messagethrowable
- the throwable
-
warn
public final void warn(java.lang.String message)
Log a warn priority event.- Parameters:
message
- the message
-
isErrorEnabled
public final boolean isErrorEnabled()
Determine if messages of priority ERROR will be logged.- Returns:
- true if ERROR messages will be logged
-
error
public final void error(java.lang.String message, java.lang.Throwable throwable)
Log a error priority event.- Parameters:
message
- the messagethrowable
- the throwable
-
error
public final void error(java.lang.String message)
Log a error priority event.- Parameters:
message
- the message
-
isFatalErrorEnabled
public final boolean isFatalErrorEnabled()
Determine if messages of priority FATAL_ERROR will be logged.- Returns:
- true if FATAL_ERROR messages will be logged
-
fatalError
public final void fatalError(java.lang.String message, java.lang.Throwable throwable)
Log a fatalError priority event.- Parameters:
message
- the messagethrowable
- the throwable
-
fatalError
public final void fatalError(java.lang.String message)
Log a fatalError priority event.- Parameters:
message
- the message
-
setAdditivity
public final void setAdditivity(boolean additivity)
Make this logger additive. I.e. Send all log events to parent loggers LogTargets regardless of whether or not the LogTargets have been overidden. This is derived from Log4js notion of Additivity.- Parameters:
additivity
- true to make logger additive, false otherwise
-
isPriorityEnabled
public final boolean isPriorityEnabled(Priority priority)
Determine if messages of priority will be logged.- Parameters:
priority
- the priority- Returns:
- true if messages will be logged
-
log
public final void log(Priority priority, java.lang.String message, java.lang.Throwable throwable)
Log a event at specific priority with a certain message and throwable.- Parameters:
priority
- the prioritymessage
- the messagethrowable
- the throwable
-
log
public final void log(Priority priority, java.lang.String message)
Log a event at specific priority with a certain message.- Parameters:
priority
- the prioritymessage
- the message
-
setPriority
public void setPriority(Priority priority)
Set the priority for this logger.- Parameters:
priority
- the priority
-
unsetPriority
public void unsetPriority()
Unset the priority of Logger. (Thus it will use it's parent's priority or DEBUG if no parent.
-
unsetPriority
public void unsetPriority(boolean recursive)
Unset the priority of Logger. (Thus it will use it's parent's priority or DEBUG if no parent. If recursive is true unset priorities of all child loggers.- Parameters:
recursive
- true to unset priority of all child loggers
-
setLogTargets
public void setLogTargets(LogTarget[] logTargets)
Set the log targets for this logger.- Parameters:
logTargets
- the Log Targets
-
unsetLogTargets
public void unsetLogTargets()
Unset the logtargets for this logger. This logger (and thus all child loggers who don't specify logtargets) will inherit from the parents LogTargets.
-
unsetLogTargets
public void unsetLogTargets(boolean recursive)
Unset the logtargets for this logger and all child loggers if recursive is set. The loggers unset (and all child loggers who don't specify logtargets) will inherit from the parents LogTargets.- Parameters:
recursive
- the recursion policy
-
getChildren
public Logger[] getChildren()
Get all the child Loggers of current logger.- Returns:
- the child loggers
-
getChildLogger
public Logger getChildLogger(java.lang.String subCategory) throws java.lang.IllegalArgumentException
Create a new child logger. The category of child logger is [current-category].subcategory- Parameters:
subCategory
- the subcategory of this logger- Returns:
- the new logger
- Throws:
java.lang.IllegalArgumentException
- if subCategory has an empty element name
-
output
private final void output(Priority priority, java.lang.String message, java.lang.Throwable throwable)
Internal method to do actual outputting.- Parameters:
priority
- the prioritymessage
- the messagethrowable
- the throwable
-
output
private final void output(LogEvent event)
-
resetChildPriorities
private void resetChildPriorities(boolean recursive)
Update priority of children if any.
-
resetPriority
private void resetPriority(boolean recursive)
Update priority of this Logger. If this loggers priority was manually set then ignore otherwise get parents priority and update all children's priority.
-
safeGetLogTargets
private LogTarget[] safeGetLogTargets()
Retrieve logtarget array contained in logger. This method is provided so that child Loggers can access a copy of parents LogTargets.- Returns:
- the array of LogTargets
-
resetChildLogTargets
private void resetChildLogTargets(boolean recursive)
Update logTargets of children if any.
-
setupErrorHandlers
private void setupErrorHandlers()
Set ErrorHandlers of LogTargets if necessary.
-
resetLogTargets
private void resetLogTargets(boolean recursive)
Update logTarget of this Logger. If this loggers logTarget was manually set then ignore otherwise get parents logTarget and update all children's logTarget.
-
-