Apache Log4cxx  Version 2.0.0
Loading...
Searching...
No Matches
log4cxx::Hierarchy Class Reference

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

#include <hierarchy.h>

Inheritance diagram for log4cxx::Hierarchy:
log4cxx::spi::LoggerRepository log4cxx::helpers::Object

Public Member Functions

 ~Hierarchy ()
void addHierarchyEventListener (const spi::HierarchyEventListenerPtr &listener) override
void removeHierarchyEventListener (const spi::HierarchyEventListenerPtr &listener) override
 Remove listener from the repository.
void ensureIsConfigured (std::function< void()> configurator) override
 Call configurator if not yet configured and configurator has not already been tried.If configurator succeeds, it must call LoggerRepository::setConfigured to ensure subsequent calls to LoggerRepository::ensureIsConfigured from overwriting the configuration.
void clear ()
 This call will clear all logger definitions from the internal hashtable.
void emitNoAppenderWarning (const Logger *logger) override
 Add a warning to internal debug output that logger does not have any Appender attached.
LoggerPtr exists (const LogString &name) override
 Does name exist in the repository?
Returns
The Logger instance if name exists in the repository.

void setThreshold (const LogString &levelStr) override
 Enable logging for logging requests with level newLevel or higher.The threshold is set the DEBUG if newLevel is not recognised by Level::getLevel. All logging requests below the threshold are immediately dropped. By default, the threshold is set to Level::getAll() which has the lowest possible rank.
void setThreshold (const LevelPtr &newLevel) override
 Enable logging for logging requests with level newLevel or higher.All logging requests below the threshold are immediately dropped. By default, the threshold is set to Level::getAll() which has the lowest possible rank.
void fireAddAppenderEvent (const Logger *logger, const Appender *appender) override
 Call addAppenderEvent on all registered listeners.
void fireRemoveAppenderEvent (const Logger *logger, const Appender *appender) override
 Call removeAppenderEvent on all registered listeners.
LevelPtr getThreshold () const override
 The current repository-wide threshold.See setThreshold for an explanation.
LoggerPtr getLogger (const LogString &name, const spi::LoggerFactoryPtr &factory={}) override
 Retrieve the name Logger instance.If a logger of that name already exists, it will be returned. Otherwise, a new logger will be instantiated, optionally by calling factory->makeNewLoggerInstance().
Parameters
nameThe logger to retrieve.
factoryIf provided, used to instantiate a new logger.

LoggerList getCurrentLoggers () const override
 All the loggers currently defined in this repository.The root logger is not included in the returned LoggerList.
LoggerPtr getRootLogger () const override
 The logger that cannot be retrieved by name.
bool isDisabled (int level) const override
 Is the repository disabled for level?The answer depends on the repository threshold and the level parameter. See also the setThreshold method.
void resetConfiguration () override
 Reset all values contained in this repository instance to their default.This removes all appenders from all categories, sets the level of all non-root categories to null, sets their additivity flag to true and sets the level of the root logger to DEBUG. Also the repository wide threshold is set its default "ALL" value.Existing categories are not removed.This method should be used sparingly and with care as it will block all logging until this is configured again.
void shutdown () override
 Shutting down a hierarchy will safely close and remove all appenders in all categories including the root logger.
virtual bool isConfigured () override
 The value of the configured status.
virtual void setConfigured (bool configured) override
 Set the configured status to true.
void updateChildren (const Logger *parent) override
 Refresh the configuration of all loggers where parent is somewhere in their ancestor chain.The ancestor chain ends at the root logger.
bool removeLogger (const LogString &name, bool ifNotUsed=true) override
 Remove the name Logger from the repository.Note: The name Logger must be retrieved from the repository after any subsequent configuration file change for the newly loaded settings to be used.
Parameters
nameThe logger to remove.
ifNotUsedIf true and use_count() indicates there are other references, do not remove the Logger and return false.
Returns
true if name Logger was removed from the repository.

Public Member Functions inherited from log4cxx::spi::LoggerRepository
virtual ~LoggerRepository ()
virtual void addHierarchyEventListener (const HierarchyEventListenerPtr &listener)=0
 Add listener to the repository.
Public Member Functions inherited from log4cxx::helpers::Object
virtual ~Object ()
virtual const helpers::Class & getClass () const =0
virtual bool instanceof (const Class &clazz) const =0
virtual const void * cast (const Class &clazz) const =0

Static Public Member Functions

static HierarchyPtr create ()
 Create a new logger hierarchy.

Detailed Description

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

The casual user does not have to deal with this class directly.

The structure of the logger hierarchy is maintained by the getLogger 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.

Constructor & Destructor Documentation

◆ ~Hierarchy()

log4cxx::Hierarchy::~Hierarchy ( )

Member Function Documentation

◆ addHierarchyEventListener()

void log4cxx::Hierarchy::addHierarchyEventListener ( const spi::HierarchyEventListenerPtr & listener)
override

◆ clear()

void log4cxx::Hierarchy::clear ( )

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.

◆ create()

HierarchyPtr log4cxx::Hierarchy::create ( )
static

Create a new logger hierarchy.

◆ emitNoAppenderWarning()

void log4cxx::Hierarchy::emitNoAppenderWarning ( const Logger * logger)
overridevirtual

Add a warning to internal debug output that logger does not have any Appender attached.

To avoid overloading the output stream, the warning is emitted only once.

Implements log4cxx::spi::LoggerRepository.

◆ ensureIsConfigured()

void log4cxx::Hierarchy::ensureIsConfigured ( std::function< void()> configurator)
overridevirtual

Call configurator if not yet configured and configurator has not already been tried.If configurator succeeds, it must call LoggerRepository::setConfigured to ensure subsequent calls to LoggerRepository::ensureIsConfigured from overwriting the configuration.

Implements log4cxx::spi::LoggerRepository.

◆ exists()

LoggerPtr log4cxx::Hierarchy::exists ( const LogString & name)
overridevirtual

Does name exist in the repository?

Returns
The Logger instance if name exists in the repository.

Implements log4cxx::spi::LoggerRepository.

◆ fireAddAppenderEvent()

void log4cxx::Hierarchy::fireAddAppenderEvent ( const Logger * logger,
const Appender * appender )
overridevirtual

Call addAppenderEvent on all registered listeners.

Reimplemented from log4cxx::spi::LoggerRepository.

◆ fireRemoveAppenderEvent()

void log4cxx::Hierarchy::fireRemoveAppenderEvent ( const Logger * logger,
const Appender * appender )
overridevirtual

Call removeAppenderEvent on all registered listeners.

Reimplemented from log4cxx::spi::LoggerRepository.

◆ getCurrentLoggers()

LoggerList log4cxx::Hierarchy::getCurrentLoggers ( ) const
overridevirtual

All the loggers currently defined in this repository.The root logger is not included in the returned LoggerList.

Implements log4cxx::spi::LoggerRepository.

◆ getLogger()

LoggerPtr log4cxx::Hierarchy::getLogger ( const LogString & name,
const spi::LoggerFactoryPtr & factory = {} )
overridevirtual

Retrieve the name Logger instance.If a logger of that name already exists, it will be returned. Otherwise, a new logger will be instantiated, optionally by calling factory->makeNewLoggerInstance().

Parameters
nameThe logger to retrieve.
factoryIf provided, used to instantiate a new logger.

Implements log4cxx::spi::LoggerRepository.

◆ getRootLogger()

LoggerPtr log4cxx::Hierarchy::getRootLogger ( ) const
overridevirtual

The logger that cannot be retrieved by name.

Implements log4cxx::spi::LoggerRepository.

◆ getThreshold()

LevelPtr log4cxx::Hierarchy::getThreshold ( ) const
overridevirtual

The current repository-wide threshold.See setThreshold for an explanation.

Implements log4cxx::spi::LoggerRepository.

◆ isConfigured()

virtual bool log4cxx::Hierarchy::isConfigured ( )
overridevirtual

The value of the configured status.

Implements log4cxx::spi::LoggerRepository.

◆ isDisabled()

bool log4cxx::Hierarchy::isDisabled ( int level) const
overridevirtual

Is the repository disabled for level?The answer depends on the repository threshold and the level parameter. See also the setThreshold method.

Implements log4cxx::spi::LoggerRepository.

◆ removeHierarchyEventListener()

void log4cxx::Hierarchy::removeHierarchyEventListener ( const spi::HierarchyEventListenerPtr & listener)
overridevirtual

Remove listener from the repository.

Implements log4cxx::spi::LoggerRepository.

◆ removeLogger()

bool log4cxx::Hierarchy::removeLogger ( const LogString & name,
bool ifNotUsed = true )
overridevirtual

Remove the name Logger from the repository.Note: The name Logger must be retrieved from the repository after any subsequent configuration file change for the newly loaded settings to be used.

Parameters
nameThe logger to remove.
ifNotUsedIf true and use_count() indicates there are other references, do not remove the Logger and return false.
Returns
true if name Logger was removed from the repository.

Implements log4cxx::spi::LoggerRepository.

◆ resetConfiguration()

void log4cxx::Hierarchy::resetConfiguration ( )
overridevirtual

Reset all values contained in this repository instance to their default.This removes all appenders from all categories, sets the level of all non-root categories to null, sets their additivity flag to true and sets the level of the root logger to DEBUG. Also the repository wide threshold is set its default "ALL" value.Existing categories are not removed.This method should be used sparingly and with care as it will block all logging until this is configured again.

Implements log4cxx::spi::LoggerRepository.

◆ setConfigured()

virtual void log4cxx::Hierarchy::setConfigured ( bool configured)
overridevirtual

Set the configured status to true.

Implements log4cxx::spi::LoggerRepository.

◆ setThreshold() [1/2]

void log4cxx::Hierarchy::setThreshold ( const LevelPtr & newLevel)
overridevirtual

Enable logging for logging requests with level newLevel or higher.All logging requests below the threshold are immediately dropped. By default, the threshold is set to Level::getAll() which has the lowest possible rank.

Implements log4cxx::spi::LoggerRepository.

◆ setThreshold() [2/2]

void log4cxx::Hierarchy::setThreshold ( const LogString & levelStr)
overridevirtual

Enable logging for logging requests with level newLevel or higher.The threshold is set the DEBUG if newLevel is not recognised by Level::getLevel. All logging requests below the threshold are immediately dropped. By default, the threshold is set to Level::getAll() which has the lowest possible rank.

Implements log4cxx::spi::LoggerRepository.

◆ shutdown()

void log4cxx::Hierarchy::shutdown ( )
overridevirtual

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

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.

Implements log4cxx::spi::LoggerRepository.

◆ updateChildren()

void log4cxx::Hierarchy::updateChildren ( const Logger * parent)
overridevirtual

Refresh the configuration of all loggers where parent is somewhere in their ancestor chain.The ancestor chain ends at the root logger.

Implements log4cxx::spi::LoggerRepository.


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