Apache log4cxx  Version 0.12.0
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 log4cxx::helpers::Object

Public Member Functions

 ~Hierarchy ()
 
void addHierarchyEventListener (const spi::HierarchyEventListenerPtr &listener)
 
void clear ()
 This call will clear all logger definitions from the internal hashtable. More...
 
void emitNoAppenderWarning (const Logger *logger)
 
LoggerPtr exists (const LogString &name)
 Check if the named logger exists in the hierarchy. More...
 
void setThreshold (const LogString &levelStr)
 The string form of setThreshold. More...
 
void setThreshold (const LevelPtr &l)
 Enable logging for logging requests with level l or higher. More...
 
void fireAddAppenderEvent (const Logger *logger, const Appender *appender)
 
void fireRemoveAppenderEvent (const Logger *logger, const Appender *appender)
 
const LevelPtrgetThreshold () const
 Returns a Level representation of the enable state. More...
 
LoggerPtr getLogger (const LogString &name)
 Return a new logger instance named as the first parameter using the default factory. More...
 
LoggerPtr getLogger (const LogString &name, const spi::LoggerFactoryPtr &factory)
 Return a new logger instance named as the first parameter using factory. More...
 
LoggerList getCurrentLoggers () const
 Returns all the currently defined loggers in this hierarchy as a LoggerList. More...
 
LoggerPtr getRootLogger () const
 Get the root of this hierarchy. More...
 
bool isDisabled (int level) const
 This method will return true if this repository is disabled for level object passed as parameter and false otherwise. More...
 
void resetConfiguration ()
 Reset all values contained in this hierarchy instance to their default. More...
 
void shutdown ()
 Used by subclasses to add a renderer to the hierarchy passed as parameter. More...
 
virtual bool isConfigured ()
 
virtual void setConfigured (bool configured)
 
- Public Member Functions inherited from log4cxx::spi::LoggerRepository
virtual ~LoggerRepository ()
 
virtual void addHierarchyEventListener (const HierarchyEventListenerPtr &listener)=0
 Add a HierarchyEventListener event to the repository. More...
 
- Public Member Functions inherited from log4cxx::helpers::Object
virtual ~Object ()
 
virtual bool instanceof (const Class &clazz) const =0
 
virtual const void * cast (const Class &clazz) const =0
 

Static Public Member Functions

static HierarchyPtr create ()
 

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)

◆ 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()

static HierarchyPtr log4cxx::Hierarchy::create ( )
static

◆ emitNoAppenderWarning()

void log4cxx::Hierarchy::emitNoAppenderWarning ( const Logger logger)
virtual

◆ exists()

LoggerPtr log4cxx::Hierarchy::exists ( const LogString name)
virtual

Check if the named logger exists in the hierarchy.

If so return its reference, otherwise returns null.

Parameters
nameThe name of the logger to search for.

Implements log4cxx::spi::LoggerRepository.

◆ fireAddAppenderEvent()

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

◆ fireRemoveAppenderEvent()

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

◆ getCurrentLoggers()

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

Returns all the currently defined loggers in this hierarchy as a LoggerList.

The root logger is not included in the returned LoggerList.

Implements log4cxx::spi::LoggerRepository.

◆ getLogger() [1/2]

LoggerPtr log4cxx::Hierarchy::getLogger ( const LogString 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.

Implements log4cxx::spi::LoggerRepository.

◆ getLogger() [2/2]

LoggerPtr log4cxx::Hierarchy::getLogger ( const LogString name,
const spi::LoggerFactoryPtr 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.

Implements log4cxx::spi::LoggerRepository.

◆ getRootLogger()

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

Get the root of this hierarchy.

Implements log4cxx::spi::LoggerRepository.

◆ getThreshold()

const LevelPtr& log4cxx::Hierarchy::getThreshold ( ) const
virtual

Returns a Level representation of the enable state.

Implements log4cxx::spi::LoggerRepository.

◆ isConfigured()

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

◆ isDisabled()

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

This method will return true if this repository is disabled for level object passed as parameter and false otherwise.

See also the setThreshold method.

Implements log4cxx::spi::LoggerRepository.

◆ resetConfiguration()

void log4cxx::Hierarchy::resetConfiguration ( )
virtual

Reset all values contained in this hierarchy 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. Moreover, message disabling is set its default "off" value.

Existing categories 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.

Implements log4cxx::spi::LoggerRepository.

◆ setConfigured()

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

◆ setThreshold() [1/2]

void log4cxx::Hierarchy::setThreshold ( const LogString levelStr)
virtual

The string form of setThreshold.

Implements log4cxx::spi::LoggerRepository.

◆ setThreshold() [2/2]

void log4cxx::Hierarchy::setThreshold ( const LevelPtr l)
virtual

Enable logging for logging requests with level l or higher.

By default all levels are enabled.

   @param l The minimum level for which logging requests are sent to

their appenders.

Implements log4cxx::spi::LoggerRepository.

◆ shutdown()

void log4cxx::Hierarchy::shutdown ( )
virtual

Used by subclasses to add a renderer to the hierarchy passed as parameter.

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

Some appenders such as SocketAppender and AsyncAppender need to be closed before the application exists. 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.

Implements log4cxx::spi::LoggerRepository.


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