DCMTK  Version 3.6.1 20120515
OFFIS DICOM Toolkit
Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Friends
dcmtk::log4cplus::Hierarchy Class Reference

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

+ Inheritance diagram for dcmtk::log4cplus::Hierarchy:

List of all members.

Public Member Functions

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

Static Public Attributes

static const LogLevel DISABLE_OFF
static const LogLevel DISABLE_OVERRIDE

Private Types

typedef OFList< LoggerProvisionNode
typedef OFMap< tstring,
ProvisionNode
ProvisionNodeMap
typedef OFMap< tstring, LoggerLoggerMap

Private Member Functions

typedef OFListIterator (Logger) ProvisionNodeIterator
virtual Logger getInstanceImpl (const tstring &name, spi::LoggerFactory &factory)
 This is the implementation of the getInstance() method.
virtual void initializeLoggerList (LoggerList &list) const
 This is the implementation of the getCurrentLoggers().
void updateParents (Logger logger)
 This method loops through all the *potential* parents of logger'.
void updateChildren (ProvisionNode &pn, Logger logger)
 We update the links for all the children that placed themselves in the provision node 'pn'.
 Hierarchy (const Hierarchy &)
Hierarchyoperator= (const Hierarchy &)

Private Attributes

DCMTK_LOG4CPLUS_MUTEX_PTR_DECLARE hashtable_mutex
OFauto_ptr< spi::LoggerFactorydefaultFactory
ProvisionNodeMap provisionNodes
LoggerMap loggerPtrs
Logger root
int disableValue
bool emittedNoAppenderWarning
bool emittedNoResourceBundleWarning

Friends

class spi::LoggerImpl
class 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.


Member Function Documentation

virtual void dcmtk::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.

virtual void dcmtk::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 system property is set to "true" or any value other than "false", then logging requests are evaluated as usual, i.e. according to the Basic Selection Rule.

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.

virtual void dcmtk::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.

virtual void dcmtk::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.

virtual void dcmtk::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.

virtual void dcmtk::log4cplus::Hierarchy::enableAll ( ) [virtual]

Undoes the effect of calling any of disable, disableAll, disableDebug and disableInfo methods.

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

virtual bool dcmtk::log4cplus::Hierarchy::exists ( const tstring name) [virtual]

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

Parameters:
nameThe name of the logger to search for.

Returns all the currently defined loggers in this hierarchy.

The root logger is not included in the returned list.

virtual Logger dcmtk::log4cplus::Hierarchy::getInstance ( const 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.
virtual Logger dcmtk::log4cplus::Hierarchy::getInstance ( const 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.
virtual Logger dcmtk::log4cplus::Hierarchy::getInstanceImpl ( const tstring name,
spi::LoggerFactory factory 
) [private, virtual]

This is the implementation of the getInstance() method.

NOTE: This method does not lock the hashtable_mutex.

virtual void dcmtk::log4cplus::Hierarchy::initializeLoggerList ( LoggerList list) const [private, virtual]

This is the implementation of the getCurrentLoggers().

NOTE: This method does not lock the hashtable_mutex.

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.

virtual void dcmtk::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.

void dcmtk::log4cplus::Hierarchy::updateChildren ( ProvisionNode pn,
Logger  logger 
) [private]

We update the links for all the children that placed themselves in the provision node 'pn'.

The second argument 'logger' is a reference for the newly created Logger, parent of all the children in 'pn'

We loop on all the children 'c' in 'pn':

If the child 'c' has been already linked to a child of 'logger' then there is no need to update 'c'.

Otherwise, we set logger's parent field to c's parent and set c's parent field to logger.

This method loops through all the *potential* parents of logger'.

There 3 possible cases:

1) No entry for the potential parent of 'logger' exists

We create a ProvisionNode for this potential parent and insert 'logger' in that provision node.

2) There is an entry of type Logger for the potential parent.

The entry is 'logger's nearest existing parent. We update logger's parent field with this entry. We also break from the loop because updating our parent's parent is our parent's responsibility.

3) There entry is of type ProvisionNode for this potential parent.

We add 'logger' to the list of children for this potential parent.


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


Generated on Tue May 15 2012 for DCMTK Version 3.6.1 20120515 by Doxygen 1.7.5.1-20111027