Logger Class Reference

Inheritance diagram for Logger:

Inheritance graph
[legend]
Collaboration diagram for Logger:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual void addAppender (const AppenderPtr &newAppender)
void assertLog (bool assertion, const String &msg)
void callAppenders (const spi::LoggingEventPtr &event)
void closeNestedAppenders ()
void debug (const String &message, const char *file=0, int line=-1)
void error (const String &message, const char *file=0, int line=-1)
void fatal (const String &message, const char *file=0, int line=-1)
void forcedLog (const LevelPtr &level, const String &message, const char *file=0, int line=-1)
bool getAdditivity () const
AppenderList getAllAppenders () const
AppenderPtr getAppender (const String &name) const
virtual const LevelPtrgetEffectiveLevel () const
spi::LoggerRepositoryPtr getLoggerRepository () const
const String & getName () const
const LoggerPtrgetParent () const
const LevelPtrgetLevel () const
helpers::ResourceBundlePtr getResourceBundle () const
void info (const String &message, const char *file=NULL, int line=-1)
bool isAttached (const AppenderPtr &appender) const
bool isDebugEnabled () const
bool isEnabledFor (const LevelPtr &level) const
bool isInfoEnabled () const
bool isWarnEnabled () const
bool isErrorEnabled () const
bool isFatalEnabled () const
void l7dlog (const LevelPtr &level, const String &key, const char *file, int line,...)
void log (const LevelPtr &level, const String &message, const char *file=0, int line=-1)
void removeAllAppenders ()
void removeAppender (const AppenderPtr &appender)
void removeAppender (const String &name)
void setAdditivity (bool additive)
virtual void setLevel (const LevelPtr &level)
void setResourceBundle (const helpers::ResourceBundlePtr &bundle)
void warn (const String &message, const char *file=NULL, int line=-1)

Static Public Member Functions

LoggerPtr getLogger (const String &name)
LoggerPtr getRootLogger ()
LoggerPtr getLogger (const String &name, spi::LoggerFactoryPtr factory)

Protected Member Functions

 Logger (const String &name)
void forcedLog (const String &fqcn, const LevelPtr &level, const String &message, const char *file=0, int line=-1)
String getResourceBundleString (const String &key) const
void setHierarchy (spi::LoggerRepository *repository)

Protected Attributes

String name
LevelPtr level
LoggerPtr parent
helpers::ResourceBundlePtr resourceBundle
bool additive

Static Protected Attributes

String FQCN = Logger::getStaticClass().getName()

Detailed Description

This is the central class in the log4cxx package. Most logging operations, except configuration, are done through this class.


Constructor & Destructor Documentation

Logger const String &  name  )  [protected]
 

This constructor created a new logger instance and sets its name.

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

Parameters:
name The name of the logger.


Member Function Documentation

void addAppender const AppenderPtr newAppender  )  [virtual]
 

Add newAppender to the list of appenders of this Logger instance.

If newAppender is already in the list of appenders, then it won't be added again.

Implements AppenderAttachable.

void assertLog bool  assertion,
const String &  msg
 

If assertion parameter is false, then

logs msg as an error statement.

Parameters:
assertion 
msg The message to print if assertion is false.

void callAppenders const spi::LoggingEventPtr event  ) 
 

Call the appenders in the hierrachy starting at this. If no appenders could be found, emit a warning.

This method calls all the appenders inherited from the hierarchy circumventing any evaluation of whether to log or not to log the particular log request.

Parameters:
event the event to log.

void closeNestedAppenders  ) 
 

Close all attached appenders implementing the AppenderAttachable interface.

void debug const String &  message,
const char *  file = 0,
int  line = -1
 

Log a message string with the DEBUG level.

This method first checks if this logger is DEBUG enabled by comparing the level of this logger with the DEBUG level. If this logger is DEBUG enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag.

Parameters:
message the message string to log.
file the file where the log statement was written.
line the line where the log statement was written.

void error const String &  message,
const char *  file = 0,
int  line = -1
 

Log a message string with the ERROR level.

This method first checks if this logger is ERROR enabled by comparing the level of this logger with the ERROR level. If this logger is ERROR enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag.

Parameters:
message the message string to log.
file the file where the log statement was written.
line the line where the log statement was written.

void fatal const String &  message,
const char *  file = 0,
int  line = -1
 

Log a message string with the FATAL level.

This method first checks if this logger is FATAL enabled by comparing the level of this logger with the FATAL level. If this logger is FATAL enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag.

Parameters:
message the message string to log.
file the file where the log statement was written.
line the line where the log statement was written.

void forcedLog const String &  fqcn,
const LevelPtr level,
const String &  message,
const char *  file = 0,
int  line = -1
[protected]
 

This method creates a new logging event and logs the event without further checks.

Parameters:
fqcn The fully qualified name of the calling logger class.
level the level to log.
message the message string to log.
file the file where the log statement was written.
line the line where the log statement was written.

void forcedLog const LevelPtr level,
const String &  message,
const char *  file = 0,
int  line = -1
 

This method creates a new logging event and logs the event without further checks.

Parameters:
level the level to log.
message the message string to log.
file the file where the log statement was written.
line the line where the log statement was written.

bool getAdditivity  )  const
 

Get the additivity flag for this Logger instance.

AppenderList getAllAppenders  )  const [virtual]
 

Get the appenders contained in this logger as an AppenderList. If no appenders can be found, then an empty AppenderList is returned.

Returns:
AppenderList An collection of the appenders in this logger.

Implements AppenderAttachable.

AppenderPtr getAppender const String &  name  )  const [virtual]
 

Look for the appender named as name.

Return the appender with that name if in the list. Return NULL otherwise.

Implements AppenderAttachable.

const LevelPtr & getEffectiveLevel  )  const [virtual]
 

Starting from this logger, search the logger hierarchy for a non-null level and return it.

The Logger class is designed so that this method executes as quickly as possible.

Exceptions:
RuntimeException if all levels are null in the hierarchy

const LevelPtr & getLevel  )  const
 

Returns the assigned Level, if any, for this Logger.

Returns:
Level - the assigned Level, can be null.

LoggerPtr getLogger const String &  name,
spi::LoggerFactoryPtr  factory
[static]
 

Like getLogger except that the type of logger instantiated depends on the type returned by the LoggerFactory#makeNewLoggerInstance 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.

LoggerPtr getLogger const String &  name  )  [static]
 

Retrieve a logger by name.

LoggerRepositoryPtr getLoggerRepository  )  const
 

Return the the LoggerRepository where this Logger is attached.

const String& getName  )  const [inline]
 

Return the logger name.

const LoggerPtr & getParent  )  const
 

Returns the parent of this logger. Note that the parent of a given logger may change during the lifetime of the logger.

The root logger will return 0.

ResourceBundlePtr getResourceBundle  )  const
 

Return the inherited ResourceBundle for this logger.

This method walks the hierarchy to find the appropriate resource bundle. It will return the resource bundle attached to the closest ancestor of this logger, much like the way priorities are searched. In case there is no bundle in the hierarchy then NULL is returned.

String getResourceBundleString const String &  key  )  const [protected]
 

Returns the string resource coresponding to key in this category's inherited resource bundle.

If the resource cannot be found, then an error message will be logged complaining about the missing resource.

See also:
getResourceBundle.

LoggerPtr getRootLogger  )  [static]
 

Retrieve the root logger.

void info const String &  message,
const char *  file = NULL,
int  line = -1
 

Log a message string with the INFO level.

This method first checks if this logger is INFO enabled by comparing the level of this logger with the INFO level. If this logger is INFO enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag.

Parameters:
message the message string to log.
file the file where the log statement was written.
line the line where the log statement was written.

bool isAttached const AppenderPtr appender  )  const [virtual]
 

Is the appender passed as parameter attached to this category?

Implements AppenderAttachable.

bool isDebugEnabled  )  const
 

Check whether this logger is enabled for the DEBUG Level.

This function is intended to lessen the computational cost of disabled log debug statements.

For some logger Logger object, when you write,

logger->debug("debug message");

You incur the cost constructing the message, concatenation in this case, regardless of whether the message is logged or not.

If you are worried about speed, then you should write

if(logger->isDebugEnabled()) { logger->debug("debug message"); }

This way you will not incur the cost of parameter construction if debugging is disabled for logger. On the other hand, if the logger is debug enabled, you will incur the cost of evaluating whether the logger is debug enabled twice. Once in isDebugEnabled and once in the debug. This is an insignificant overhead since evaluating a logger takes about 1%% of the time it takes to actually log.

Returns:
bool - true if this logger is debug enabled, false otherwise.

bool isEnabledFor const LevelPtr level  )  const
 

Check whether this logger is enabled for a given Level passed as parameter.

See also isDebugEnabled.

Returns:
bool True if this logger is enabled for level.

bool isErrorEnabled  )  const
 

Check whether this logger is enabled for the error Level. See also isDebugEnabled.

Returns:
bool - true if this logger is enabled for level error, false otherwise.

bool isFatalEnabled  )  const
 

Check whether this logger is enabled for the fatal Level. See also isDebugEnabled.

Returns:
bool - true if this logger is enabled for level fatal, false otherwise.

bool isInfoEnabled  )  const
 

Check whether this logger is enabled for the info Level. See also isDebugEnabled.

Returns:
bool - true if this logger is enabled for level info, false otherwise.

bool isWarnEnabled  )  const
 

Check whether this logger is enabled for the warn Level. See also isDebugEnabled.

Returns:
bool - true if this logger is enabled for level warn, false otherwise.

void l7dlog const LevelPtr level,
const String &  key,
const char *  file,
int  line,
... 
 

Log a localized and parameterized message.

First, the user supplied key is searched in the resource bundle. Next, the resulting pattern is formatted using helpers::StringHelper::format method with the user supplied object array params.

Parameters:
level The level of the logging request.
key The key to be searched in the resourceBundle.
file The source file of the logging request, may be null.
line The number line of the logging request.
See also:
setResourceBundle

void log const LevelPtr level,
const String &  message,
const char *  file = 0,
int  line = -1
 

This is the most generic printing method. It is intended to be invoked by wrapper classes.

Parameters:
level The level of the logging request.
message The message of the logging request.
file The source file of the logging request, may be null.
line The number line of the logging request.

void removeAllAppenders  )  [virtual]
 

Remove all previously added appenders from this logger instance.

This is useful when re-reading configuration information.

Implements AppenderAttachable.

void removeAppender const String &  name  )  [virtual]
 

Remove the appender with the name passed as parameter form the list of appenders.

Implements AppenderAttachable.

void removeAppender const AppenderPtr appender  )  [virtual]
 

Remove the appender passed as parameter form the list of appenders.

Implements AppenderAttachable.

void setAdditivity bool  additive  ) 
 

Set the additivity flag for this Logger instance.

void setHierarchy spi::LoggerRepository repository  )  [protected]
 

Only the Hierarchy class can set the hierarchy of a logger.

void setLevel const LevelPtr level  )  [virtual]
 

Set the level of this Logger. If you are passing any of Level::DEBUG, Level::INFO, Level::WARN, Level::ERROR, Level::FATAL as a parameter, you need to case them as Level.

As in

   logger->setLevel(Level::DEBUG);

Null values are admitted.

Reimplemented in RootCategory.

void setResourceBundle const helpers::ResourceBundlePtr bundle  )  [inline]
 

Set the resource bundle to be used with localized logging method l7dlog.

void warn const String &  message,
const char *  file = NULL,
int  line = -1
 

Log a message string with the WARN level.

This method first checks if this logger is WARN enabled by comparing the level of this logger with the WARN level. If this logger is WARN enabled, it proceeds to call all the registered appenders in this logger and also higher in the hierarchy depending on the value of the additivity flag.

Parameters:
message the message string to log.
file the file where the log statement was written.
line the line where the log statement was written.


Member Data Documentation

bool additive [protected]
 

Additivity is set to true by default, that is children inherit the appenders of their ancestors by default. If this variable is set to false then the appenders found in the ancestors of this logger are not used. However, the children of this logger will inherit its appenders, unless the children have their additivity flag set to false too. See the user manual for more details.

String FQCN = Logger::getStaticClass().getName() [static, protected]
 

The fully qualified name of the Category class. See also the getFQCN method.

LevelPtr level [protected]
 

The assigned level of this logger. The level variable need not be assigned a value in which case it is inherited form the hierarchy.

String name [protected]
 

The name of this logger.

LoggerPtr parent [protected]
 

The parent of this logger. All loggers have at least one ancestor which is the root logger.

helpers::ResourceBundlePtr resourceBundle [protected]
 

The resourceBundle for localized messages.

See also:
setResourceBundle, getResourceBundle


The documentation for this class was generated from the following files:
  • logger.h
  • logger.cpp

Copyright © 1999-2004, Apache Software Foundation