A logger class. More...
#include <Logger.h>
Public Member Functions | |
Logger (Logger &parent, const std::string &subdomain) | |
Logger (Logger &parent, const std::string &subdomain, LogLevel threshold) | |
~Logger () | |
void | addDestination (LogDestination &destination) |
void | addDestinations (const std::list< LogDestination * > &destinations) |
const std::list < LogDestination * > & | getDestinations (void) const |
void | removeDestinations (void) |
void | deleteDestinations (void) |
void | setThreshold (LogLevel threshold) |
LogLevel | getThreshold () const |
void | setThreadContext (void) |
void | msg (LogMessage message) |
void | msg (LogLevel level, const std::string &str) |
Static Public Member Functions | |
static Logger & | getRootLogger () |
static void | setThresholdForDomain (LogLevel threshold, const std::list< std::string > &subdomains) |
static void | setThresholdForDomain (LogLevel threshold, const std::string &domain) |
A logger class.
This class defines a Logger to which LogMessages can be sent.
Every Logger (except for the rootLogger) has a parent Logger. The domain of a Logger (a string that indicates the origin of LogMessages) is composed by adding a subdomain to the domain of its parent Logger.
A Logger also has a threshold. Every LogMessage that have a level that is greater than or equal to the threshold is forwarded to any LogDestination connected to this Logger as well as to the parent Logger.
Typical usage of the Logger class is to declare a global Logger object for each library/module/component to be used by all classes and methods there.
Arc::Logger::Logger | ( | Logger & | parent, | |
const std::string & | subdomain | |||
) |
Arc::Logger::~Logger | ( | ) |
Destroys a logger.
Destructor
void Arc::Logger::addDestination | ( | LogDestination & | destination | ) |
Adds a LogDestination.
Adds a LogDestination to which to forward LogMessages sent to this logger (if they pass the threshold). Since LogDestinatoins should not be copied, the new LogDestination is passed by reference and a pointer to it is kept for later use. It is therefore important that the LogDestination passed to this Logger exists at least as long as the Logger iteslf.
void Arc::Logger::addDestinations | ( | const std::list< LogDestination * > & | destinations | ) |
Adds LogDestinations.
const std::list<LogDestination*>& Arc::Logger::getDestinations | ( | void | ) | const |
Obtains current LogDestinations.
Returns list of pointers to LogDestination objects. Returned result refers directly to internal member of Logger intance. Hence it should not be used after this Logger is destroyed.
static Logger& Arc::Logger::getRootLogger | ( | ) | [static] |
LogLevel Arc::Logger::getThreshold | ( | ) | const |
void Arc::Logger::msg | ( | LogLevel | level, | |
const std::string & | str | |||
) | [inline] |
Logs a message text.
Logs a message text string at the specified LogLevel. This is a convenience method to save some typing. It simply creates a LogMessage and sends it to the other msg() method.
level | The level of the message. | |
str | The message text. |
References msg().
void Arc::Logger::msg | ( | LogMessage | message | ) |
Sends a LogMessage.
Sends a LogMessage.
The | LogMessage to send. |
Referenced by msg(), and Arc::stringto().
void Arc::Logger::setThreadContext | ( | void | ) |
Creates per-thread context.
Creates new context for this logger which becomes effective for operations initiated by this thread. All new threads started by this one will inherit new context. Context stores current threshold and pointers to destinations. Hence new context is identical to current one. One can modify new context using setThreshold(), removeDestinations() and addDestination(). All such operations will not affect old context.
void Arc::Logger::setThreshold | ( | LogLevel | threshold | ) |
static void Arc::Logger::setThresholdForDomain | ( | LogLevel | threshold, | |
const std::string & | domain | |||
) | [static] |
Sets the threshold for domain.
This method sets the default threshold of the domain. All new loggers created with specified domain will have specified threshold set by default. The domain is composed of all subdomains of all loggers in chain by merging them with '.' as separator.
threshold | The threshold | |
domain | The domain of logger |
static void Arc::Logger::setThresholdForDomain | ( | LogLevel | threshold, | |
const std::list< std::string > & | subdomains | |||
) | [static] |
Sets the threshold for domain.
This method sets the default threshold of the domain. All new loggers created with specified domain will have specified threshold set by default. The subdomains of all loggers in chain are matched against list of provided subdomains.
threshold | The threshold | |
subdomains | The subdomains of all loggers in chain |