ARC SDK
|
A logger class. More...
#include <Logger.h>
Public Member Functions | |
Logger (Logger &parent, const std::string &subdomain) | |
Creates a logger. More... | |
Logger (Logger &parent, const std::string &subdomain, LogLevel threshold) | |
Creates a logger. More... | |
~Logger () | |
Destroys a logger. | |
void | addDestination (LogDestination &destination) |
Adds a LogDestination. More... | |
void | addDestinations (const std::list< LogDestination * > &destinations) |
Adds LogDestinations. More... | |
void | setDestinations (const std::list< LogDestination * > &destinations) |
Set LogDestinations. More... | |
const std::list < LogDestination * > & | getDestinations (void) const |
Obtains current LogDestinations. More... | |
void | removeDestinations (void) |
Removes all LogDestinations. | |
void | deleteDestinations (void) |
Remove all LogDestinations and delete LogDestination objects. | |
void | setThreshold (LogLevel threshold) |
Sets the logging threshold. More... | |
LogLevel | getThreshold () const |
Returns the threshold of this logger. | |
void | setThreadContext (void) |
Creates per-thread context. More... | |
void | msg (LogMessage message) |
Sends a LogMessage. More... | |
void | msg (LogLevel level, const std::string &str) |
Logs a message text. More... | |
Static Public Member Functions | |
static Logger & | getRootLogger () |
The root Logger. More... | |
static void | setThresholdForDomain (LogLevel threshold, const std::list< std::string > &subdomains) |
Sets the threshold for domain. More... | |
static void | setThresholdForDomain (LogLevel threshold, const std::string &domain) |
Sets the threshold for domain. More... | |
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.
Logger messages may be localised according to the current locale. Some locales are better supported than others.
Example code for setting up logger in main():
Arc::Logger::Logger | ( | Logger & | parent, |
const std::string & | subdomain | ||
) |
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 LogDestinations 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 itself.
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 instance. Hence it should not be used after this Logger is destroyed.
|
static |
void Arc::Logger::msg | ( | LogMessage | message | ) |
Sends a LogMessage.
message | The LogMessage to send. |
|
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() methods. It is also possible to use msg() with multiple arguments and printf-style string formatting, for example
level | The level of the message. |
str | The message text. |
void Arc::Logger::setDestinations | ( | const std::list< LogDestination * > & | destinations | ) |
Set LogDestinations.
A safe atomic way to remove and add LogDestinations.
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 |
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 |
|
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 |