RSC  0.16.0
rsc::logging::LoggerFactory Class Reference

Factory to create logger instances. More...

#include <LoggerFactory.h>

Inheritance diagram for rsc::logging::LoggerFactory:
Inheritance graph
Collaboration diagram for rsc::logging::LoggerFactory:
Collaboration graph

Classes

class  ReconfigurationVisitor
 
class  ReselectVisitor
 

Public Member Functions

virtual ~LoggerFactory ()
 
LoggerPtr getLogger (const std::string &name="")
 Get a logger for the given name. More...
 
void reconfigure (const Logger::Level &level)
 Simple hack to reconfigure all known loggers and new instances with a logging level. More...
 
void reconfigureFromFile (const std::string &fileName)
 Reconfigures the logging system from a configuration file. More...
 
void reselectLoggingSystem (const std::string &nameHint="")
 Reselected the automatically chosen logging system to adapt to newly available ones. More...
 
std::string getLoggingSystemName ()
 Returns the name of the currently selected logging system. More...
 
void clearKnownLoggers ()
 Do not use this, for testing only! More...
 
- Public Member Functions inherited from rsc::patterns::Singleton< LoggerFactory >
virtual ~Singleton ()
 

Static Public Attributes

static const std::string DEFAULT_LOGGING_SYSTEM
 Parameter to pass as name hint to reselectLoggingSystem for selecting the default system. More...
 
static const Logger::Level DEFAULT_LEVEL = Logger::LEVEL_WARN
 Default level when the system is used without prior initialization. More...
 

Private Member Functions

 LoggerFactory ()
 
LoggerProxyPtr createLogger (const LoggerTreeNode::NamePath &path, LoggerTreeNodePtr node)
 

Private Attributes

boost::shared_ptr< LoggingSystemloggingSystem
 
boost::recursive_mutex mutex
 
LoggerTreeNodePtr loggerTree
 

Friends

class patterns::Singleton< LoggerFactory >
 

Additional Inherited Members

- Static Public Member Functions inherited from rsc::patterns::Singleton< LoggerFactory >
static LoggerFactory & getInstance ()
 Retrieve the singleton instance, creating it if necessary. More...
 
static void killInstance ()
 This function can be used to make sure the instance is deleted at a particular time. More...
 

Detailed Description

Factory to create logger instances.

On singleton creation selects a logger according to the heuristic mentioned for reselectLoggingSystem.

Author
jwienke

Definition at line 83 of file LoggerFactory.h.

Constructor & Destructor Documentation

rsc::logging::LoggerFactory::LoggerFactory ( )
private

Definition at line 118 of file LoggerFactory.cpp.

rsc::logging::LoggerFactory::~LoggerFactory ( )
virtual

Definition at line 137 of file LoggerFactory.cpp.

Member Function Documentation

void rsc::logging::LoggerFactory::clearKnownLoggers ( )

Do not use this, for testing only!

Definition at line 263 of file LoggerFactory.cpp.

LoggerProxyPtr rsc::logging::LoggerFactory::createLogger ( const LoggerTreeNode::NamePath path,
LoggerTreeNodePtr  node 
)
private

Definition at line 203 of file LoggerFactory.cpp.

LoggerPtr rsc::logging::LoggerFactory::getLogger ( const std::string &  name = "")

Get a logger for the given name.

If a logger with this name already exists, the existing instance is returned.

Receiving a logger is a quite expensive operation if a logger with the specified name did not exist before at runtime. Hence, do not use constantly changing names for loggers with a short lifetime.

Parameters
namename of the logger, empty string means root logger
Returns
logger instance

Definition at line 219 of file LoggerFactory.cpp.

string rsc::logging::LoggerFactory::getLoggingSystemName ( )

Returns the name of the currently selected logging system.

Returns
logging system name

Definition at line 258 of file LoggerFactory.cpp.

void rsc::logging::LoggerFactory::reconfigure ( const Logger::Level level)

Simple hack to reconfigure all known loggers and new instances with a logging level.

Only loggers which had a manually assigned level will actually be assigned with the new level. All others use the inheritance tree to get a level. Effectively this will result in all loggers appearing with the same level but semantics for changing certain levels in the logger tree are preserved.

Parameters
levelnew level for all loggers

Definition at line 250 of file LoggerFactory.cpp.

void rsc::logging::LoggerFactory::reconfigureFromFile ( const std::string &  fileName)

Reconfigures the logging system from a configuration file.

Parameters
fileNamename of the configuration file
Exceptions
std::invalid_argumentinvalid file path

Definition at line 268 of file LoggerFactory.cpp.

References rsc::config::ConfigFileSource::provideOptions().

Here is the call graph for this function:

void rsc::logging::LoggerFactory::reselectLoggingSystem ( const std::string &  nameHint = "")

Reselected the automatically chosen logging system to adapt to newly available ones.

A hint can be given on the name of the logging system to select.

If no hint is given the first found logging system which is not the default will be selected. If no such system exists, the default is used. The name hint overrides these settings if a logging system matching the hint is found.

This method will NOT change previously gathered loggers.

Parameters
nameHinthint for the name of the logging system to select. If the string is empty, it will not be used. If it is DEFAULT_LOGGING_SYSTEM, the default logging system will be selected even if other systems are available.

Definition at line 160 of file LoggerFactory.cpp.

References rsc::logging::loggingSystemRegistry().

Here is the call graph for this function:

Friends And Related Function Documentation

friend class patterns::Singleton< LoggerFactory >
friend

Definition at line 89 of file LoggerFactory.h.

Member Data Documentation

const Logger::Level rsc::logging::LoggerFactory::DEFAULT_LEVEL = Logger::LEVEL_WARN
static

Default level when the system is used without prior initialization.

Definition at line 154 of file LoggerFactory.h.

const string rsc::logging::LoggerFactory::DEFAULT_LOGGING_SYSTEM
static
Initial value:

Parameter to pass as name hint to reselectLoggingSystem for selecting the default system.

Definition at line 149 of file LoggerFactory.h.

LoggerTreeNodePtr rsc::logging::LoggerFactory::loggerTree
private

Definition at line 179 of file LoggerFactory.h.

boost::shared_ptr<LoggingSystem> rsc::logging::LoggerFactory::loggingSystem
private

Definition at line 176 of file LoggerFactory.h.

boost::recursive_mutex rsc::logging::LoggerFactory::mutex
private

Definition at line 178 of file LoggerFactory.h.


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