log4cplus  2.1.0
Public Member Functions | Static Public Attributes | Friends | List of all members
log4cplus::Hierarchy Class Reference

This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy. More...

#include <hierarchy.h>

Public Member Functions

 Hierarchy ()
 Create a new Logger hierarchy. More...
 
virtual ~Hierarchy ()
 
virtual void clear ()
 This call will clear all logger definitions from the internal hashtable. More...
 
virtual bool exists (const log4cplus::tstring &name)
 Returns true if the named logger exists (in the default hierarchy). More...
 
virtual void disable (const log4cplus::tstring &loglevelStr)
 Similar to disable(LogLevel) except that the LogLevel argument is given as a log4cplus::tstring. More...
 
virtual void disable (LogLevel ll)
 Disable all logging requests of LogLevel equal to or below the ll parameter p, for all loggers in this hierarchy. More...
 
virtual void disableAll ()
 Disable all logging requests regardless of logger and LogLevel. More...
 
virtual void disableDebug ()
 Disable all Debug logging requests regardless of logger. More...
 
virtual void disableInfo ()
 Disable all Info logging requests regardless of logger. More...
 
virtual void enableAll ()
 Undoes the effect of calling any of disable, {}, #disableDebug} and #disableInfo} methods. More...
 
virtual Logger getInstance (const log4cplus::tstring &name)
 Return a new logger instance named as the first parameter using the default factory. More...
 
virtual Logger getInstance (const log4cplus::tstring &name, spi::LoggerFactory &factory)
 Return a new logger instance named as the first parameter using factory. More...
 
virtual LoggerList getCurrentLoggers ()
 Returns all the currently defined loggers in this hierarchy. More...
 
virtual bool isDisabled (LogLevel level)
 Is the LogLevel specified by level enabled? More...
 
virtual Logger getRoot () const
 Get the root of this hierarchy. More...
 
virtual void resetConfiguration ()
 Reset all values contained in this hierarchy instance to their default. More...
 
virtual void setLoggerFactory (std::unique_ptr< spi::LoggerFactory > factory)
 Set the default LoggerFactory instance. More...
 
virtual spi::LoggerFactorygetLoggerFactory ()
 Returns the default LoggerFactory instance. More...
 
virtual void shutdown ()
 Shutting down a hierarchy will safely close and remove all appenders in all loggers including the root logger. More...
 

Static Public Attributes

static const LogLevel DISABLE_OFF
 
static const LogLevel DISABLE_OVERRIDE
 

Friends

class log4cplus::spi::LoggerImpl
 
class log4cplus::HierarchyLocker
 

Detailed Description

This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.

The casual user should not have to deal with this class directly. However, if you are in an environment where multiple applications run in the same process, then read on.

The structure of the logger hierarchy is maintained by the getInstance method. The hierarchy is such that children link to their parent but parents do not have any pointers to their children. Moreover, loggers can be instantiated in any order, in particular descendant before ancestor.

In case a descendant is created before a particular ancestor, then it creates a provision node for the ancestor and adds itself to the provision node. Other descendants of the same ancestor add themselves to the previously created provision node.

Definition at line 63 of file hierarchy.h.

Constructor & Destructor Documentation

◆ Hierarchy()

log4cplus::Hierarchy::Hierarchy ( )

Create a new Logger hierarchy.

◆ ~Hierarchy()

virtual log4cplus::Hierarchy::~Hierarchy ( )
virtual

Member Function Documentation

◆ clear()

virtual void log4cplus::Hierarchy::clear ( )
virtual

This call will clear all logger definitions from the internal hashtable.

Invoking this method will irrevocably mess up the logger hierarchy.

You should really know what you are doing before invoking this method.

◆ disable() [1/2]

virtual void log4cplus::Hierarchy::disable ( const log4cplus::tstring loglevelStr)
virtual

Similar to disable(LogLevel) except that the LogLevel argument is given as a log4cplus::tstring.

◆ disable() [2/2]

virtual void log4cplus::Hierarchy::disable ( LogLevel  ll)
virtual

Disable all logging requests of LogLevel equal to or below the ll parameter p, for all loggers in this hierarchy.

Logging requests of higher LogLevel then p remain unaffected.

Nevertheless, if the BasicConfigurator::DISABLE_OVERRIDE_KEY property is set to true, then logging requests are evaluated as usual.

The "disable" family of methods are there for speed. They allow printing methods such as debug, info, etc. to return immediately after an integer comparison without walking the logger hierarchy. In most modern computers an integer comparison is measured in nanoseconds where as a logger walk is measured in units of microseconds.

◆ disableAll()

virtual void log4cplus::Hierarchy::disableAll ( )
virtual

Disable all logging requests regardless of logger and LogLevel.

This method is equivalent to calling disable with the argument FATAL_LOG_LEVEL, the highest possible LogLevel.

◆ disableDebug()

virtual void log4cplus::Hierarchy::disableDebug ( )
virtual

Disable all Debug logging requests regardless of logger.

This method is equivalent to calling disable with the argument DEBUG_LOG_LEVEL.

◆ disableInfo()

virtual void log4cplus::Hierarchy::disableInfo ( )
virtual

Disable all Info logging requests regardless of logger.

This method is equivalent to calling disable with the argument INFO_LOG_LEVEL.

◆ enableAll()

virtual void log4cplus::Hierarchy::enableAll ( )
virtual

Undoes the effect of calling any of disable, {}, #disableDebug} and #disableInfo} methods.

More precisely, invoking this method sets the Logger class internal variable called disable to its default "off" value.

◆ exists()

virtual bool log4cplus::Hierarchy::exists ( const log4cplus::tstring name)
virtual

Returns true if the named logger exists (in the default hierarchy).

Parameters
nameThe name of the logger to search for.

◆ getCurrentLoggers()

virtual LoggerList log4cplus::Hierarchy::getCurrentLoggers ( )
virtual

Returns all the currently defined loggers in this hierarchy.

The root logger is not included in the returned list.

◆ getInstance() [1/2]

virtual Logger log4cplus::Hierarchy::getInstance ( const log4cplus::tstring name)
virtual

Return a new logger instance named as the first parameter using the default factory.

If a logger of that name already exists, then it will be returned. Otherwise, a new logger will be instantiated and then linked with its existing ancestors as well as children.

Parameters
nameThe name of the logger to retrieve.

◆ getInstance() [2/2]

virtual Logger log4cplus::Hierarchy::getInstance ( const log4cplus::tstring name,
spi::LoggerFactory factory 
)
virtual

Return a new logger instance named as the first parameter using factory.

If a logger of that name already exists, then it will be returned. Otherwise, a new logger will be instantiated by the factory parameter and linked with its existing ancestors as well as children.

Parameters
nameThe name of the logger to retrieve.
factoryThe factory that will make the new logger instance.

◆ getLoggerFactory()

virtual spi::LoggerFactory* log4cplus::Hierarchy::getLoggerFactory ( )
virtual

Returns the default LoggerFactory instance.

◆ getRoot()

virtual Logger log4cplus::Hierarchy::getRoot ( ) const
virtual

Get the root of this hierarchy.

◆ isDisabled()

virtual bool log4cplus::Hierarchy::isDisabled ( LogLevel  level)
virtual

Is the LogLevel specified by level enabled?

◆ resetConfiguration()

virtual void log4cplus::Hierarchy::resetConfiguration ( )
virtual

Reset all values contained in this hierarchy instance to their default.

This removes all appenders from all loggers, sets the LogLevel of all non-root loggers to NOT_SET_LOG_LEVEL, sets their additivity flag to true and sets the LogLevel of the root logger to DEBUG_LOG_LEVEL. Moreover, message disabling is set its default "off" value.

Existing loggers are not removed. They are just reset.

This method should be used sparingly and with care as it will block all logging until it is completed.

◆ setLoggerFactory()

virtual void log4cplus::Hierarchy::setLoggerFactory ( std::unique_ptr< spi::LoggerFactory factory)
virtual

Set the default LoggerFactory instance.

◆ shutdown()

virtual void log4cplus::Hierarchy::shutdown ( )
virtual

Shutting down a hierarchy will safely close and remove all appenders in all loggers including the root logger.

Some appenders such as SocketAppender need to be closed before the application exits. Otherwise, pending logging events might be lost.

The shutdown method is careful to close nested appenders before closing regular appenders. This is allows configurations where a regular appender is attached to a logger and again to a nested appender.

Friends And Related Function Documentation

◆ log4cplus::HierarchyLocker

friend class log4cplus::HierarchyLocker
friend

Definition at line 315 of file hierarchy.h.

◆ log4cplus::spi::LoggerImpl

friend class log4cplus::spi::LoggerImpl
friend

Definition at line 314 of file hierarchy.h.

Member Data Documentation

◆ DISABLE_OFF

const LogLevel log4cplus::Hierarchy::DISABLE_OFF
static

Definition at line 68 of file hierarchy.h.

◆ DISABLE_OVERRIDE

const LogLevel log4cplus::Hierarchy::DISABLE_OVERRIDE
static

Definition at line 69 of file hierarchy.h.


The documentation for this class was generated from the following file: