org.apache.log

Class Logger

public class Logger extends Object

The object interacted with by client objects to perform logging.

Author: Avalon Development Team Peter Donald

Field Summary
static charCATEGORY_SEPARATOR
Separator character use to separate different categories
static Logger[]EMPTY_SET
booleanm_additivity
True means LogEvents will be sent to parents LogTargets aswell as the ones set for this Logger.
Stringm_category
Logger[]m_children
ErrorHandlerm_errorHandler
LoggerListenerm_loggerListener
LogTarget[]m_logTargets
booleanm_logTargetsForceSet
Loggerm_parent
Prioritym_priority
booleanm_priorityForceSet
Constructor Summary
Logger(ErrorHandler errorHandler, LoggerListener loggerListener, String category, LogTarget[] logTargets, Logger parent)
Protected constructor for use inside the logging toolkit.
Method Summary
voiddebug(String message, Throwable throwable)
Log a debug priority event.
voiddebug(String message)
Log a debug priority event.
voiderror(String message, Throwable throwable)
Log a error priority event.
voiderror(String message)
Log a error priority event.
voidfatalError(String message, Throwable throwable)
Log a fatalError priority event.
voidfatalError(String message)
Log a fatalError priority event.
voidfireEvent(LogEvent event, LogTarget[] targets)
LoggergetChildLogger(String subCategory)
Create a new child logger.
Logger[]getChildren()
Get all the child Loggers of current logger.
voidinfo(String message, Throwable throwable)
Log a info priority event.
voidinfo(String message)
Log a info priority event.
booleanisDebugEnabled()
Determine if messages of priority DEBUG will be logged.
booleanisErrorEnabled()
Determine if messages of priority ERROR will be logged.
booleanisFatalErrorEnabled()
Determine if messages of priority FATAL_ERROR will be logged.
booleanisInfoEnabled()
Determine if messages of priority INFO will be logged.
booleanisPriorityEnabled(Priority priority)
Determine if messages of priority o?
booleanisWarnEnabled()
Determine if messages of priority WARN will be logged.
voidlog(Priority priority, String message, Throwable throwable)
Log a event at specific priority with a certain message and throwable.
voidlog(Priority priority, String message)
Log a event at specific priority with a certain message.
voidoutput(Priority priority, String message, Throwable throwable)
Internal method to do actual outputting.
voidoutput(LogEvent event)
voidresetChildLogTargets(boolean recursive)
Update logTargets of children if any.
voidresetChildPriorities(boolean recursive)
Update priority of children if any.
voidresetLogTargets(boolean recursive)
Update logTarget of this Logger.
voidresetPriority(boolean recursive)
Update priority of this Logger.
LogTarget[]safeGetLogTargets()
Retrieve logtarget array contained in logger.
voidsetAdditivity(boolean additivity)
Make this logger additive.
voidsetLogTargets(LogTarget[] logTargets)
Set the log targets for this logger.
voidsetPriority(Priority priority)
Set the priority for this logger.
voidsetupErrorHandlers()
Set ErrorHandlers of LogTargets if necessary.
voidunsetLogTargets()
Unset the logtargets for this logger.
voidunsetLogTargets(boolean recursive)
Unset the logtargets for this logger and all child loggers if recursive is set.
voidunsetPriority()
Unset the priority of Logger.
voidunsetPriority(boolean recursive)
Unset the priority of Logger.
voidwarn(String message, Throwable throwable)
Log a warn priority event.
voidwarn(String message)
Log a warn priority event.

Field Detail

CATEGORY_SEPARATOR

public static final char CATEGORY_SEPARATOR
Separator character use to separate different categories

EMPTY_SET

private static final Logger[] EMPTY_SET

m_additivity

private boolean m_additivity
True means LogEvents will be sent to parents LogTargets aswell as the ones set for this Logger.

m_category

private final String m_category

m_children

private Logger[] m_children

m_errorHandler

private final ErrorHandler m_errorHandler

m_loggerListener

private final LoggerListener m_loggerListener

m_logTargets

private LogTarget[] m_logTargets

m_logTargetsForceSet

private boolean m_logTargetsForceSet

m_parent

private final Logger m_parent

m_priority

private Priority m_priority

m_priorityForceSet

private boolean m_priorityForceSet

Constructor Detail

Logger

Logger(ErrorHandler errorHandler, LoggerListener loggerListener, 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 errors category the fully qualified name of category logTargets the LogTargets associated with logger parent the parent logger (used for inheriting from)

Method Detail

debug

public final void debug(String message, Throwable throwable)
Log a debug priority event.

Parameters: message the message throwable the throwable

debug

public final void debug(String message)
Log a debug priority event.

Parameters: message the message

error

public final void error(String message, Throwable throwable)
Log a error priority event.

Parameters: message the message throwable the throwable

error

public final void error(String message)
Log a error priority event.

Parameters: message the message

fatalError

public final void fatalError(String message, Throwable throwable)
Log a fatalError priority event.

Parameters: message the message throwable the throwable

fatalError

public final void fatalError(String message)
Log a fatalError priority event.

Parameters: message the message

fireEvent

private final void fireEvent(LogEvent event, LogTarget[] targets)

getChildLogger

public Logger getChildLogger(String subCategory)
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: IllegalArgumentException if subCategory has an empty element name

getChildren

public Logger[] getChildren()
Get all the child Loggers of current logger.

Returns: the child loggers

info

public final void info(String message, Throwable throwable)
Log a info priority event.

Parameters: message the message throwable the throwable

info

public final void info(String message)
Log a info priority event.

Parameters: message the message

isDebugEnabled

public final boolean isDebugEnabled()
Determine if messages of priority DEBUG will be logged.

Returns: true if DEBUG messages will be logged

isErrorEnabled

public final boolean isErrorEnabled()
Determine if messages of priority ERROR will be logged.

Returns: true if ERROR messages will be logged

isFatalErrorEnabled

public final boolean isFatalErrorEnabled()
Determine if messages of priority FATAL_ERROR will be logged.

Returns: true if FATAL_ERROR messages will be logged

isInfoEnabled

public final boolean isInfoEnabled()
Determine if messages of priority INFO will be logged.

Returns: true if INFO messages will be logged

isPriorityEnabled

public final boolean isPriorityEnabled(Priority priority)
Determine if messages of priority o?=will be logged.

Parameters: priority the priority

Returns: true if messages will be logged

isWarnEnabled

public final boolean isWarnEnabled()
Determine if messages of priority WARN will be logged.

Returns: true if WARN messages will be logged

log

public final void log(Priority priority, String message, Throwable throwable)
Log a event at specific priority with a certain message and throwable.

Parameters: priority the priority message the message throwable the throwable

log

public final void log(Priority priority, String message)
Log a event at specific priority with a certain message.

Parameters: priority the priority message the message

output

private final void output(Priority priority, String message, Throwable throwable)
Internal method to do actual outputting.

Parameters: priority the priority message the message throwable the throwable

output

private final void output(LogEvent event)

resetChildLogTargets

private void resetChildLogTargets(boolean recursive)
Update logTargets of children if any.

resetChildPriorities

private void resetChildPriorities(boolean recursive)
Update priority of children if any.

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.

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

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

setLogTargets

public void setLogTargets(LogTarget[] logTargets)
Set the log targets for this logger.

Parameters: logTargets the Log Targets

setPriority

public void setPriority(Priority priority)
Set the priority for this logger.

Parameters: priority the priority

setupErrorHandlers

private void setupErrorHandlers()
Set ErrorHandlers of LogTargets if necessary.

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

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

warn

public final void warn(String message, Throwable throwable)
Log a warn priority event.

Parameters: message the message throwable the throwable

warn

public final void warn(String message)
Log a warn priority event.

Parameters: message the message