ARC SDK
Public Member Functions | Static Public Member Functions
Arc::Logger Class Reference

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. More...
 
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. More...
 
void deleteDestinations (void)
 Remove all LogDestinations and delete LogDestination objects. More...
 
void setThreshold (LogLevel threshold)
 Sets the logging threshold. More...
 
LogLevel getThreshold () const
 Returns the threshold of this logger. More...
 
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...
 
template<class T0 >
void msg (LogLevel level, const std::string &str, const T0 &t0)
 
template<class T0 , class T1 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1)
 
template<class T0 , class T1 , class T2 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2)
 
template<class T0 , class T1 , class T2 , class T3 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3)
 
template<class T0 , class T1 , class T2 , class T3 , class T4 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4)
 
template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5)
 
template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6)
 
template<class T0 , class T1 , class T2 , class T3 , class T4 , class T5 , class T6 , class T7 >
void msg (LogLevel level, const std::string &str, const T0 &t0, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7)
 

Static Public Member Functions

static LoggergetRootLogger ()
 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...
 

Detailed Description

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

// Set up stderr as a log stream
Arc::LogStream logcerr(std::cerr);
// Log message is prefixed by level only
logcerr.setFormat(Arc::ShortFormat);
// Add the stderr destination to the root logger
// Set the logging threshold to WARNING
// Logger to use in main() - it inherits all properties from the root Logger
// this message will not be logged since it is below the threshold
logger.msg(Arc::INFO, "main started");
int i = 5;
// This message will be logged
logger.msg(Arc::ERROR, "Oops, an error occurred when i was %i", i);

Constructor & Destructor Documentation

Arc::Logger::Logger ( Logger parent,
const std::string &  subdomain 
)

Creates a logger.

The threshold is inherited from its parent Logger.

Parameters
parentThe parent Logger of the new Logger.
subdomainThe subdomain of the new logger.
Arc::Logger::Logger ( Logger parent,
const std::string &  subdomain,
LogLevel  threshold 
)

Creates a logger.

Parameters
parentThe parent Logger of the new Logger.
subdomainThe subdomain of the new logger.
thresholdThe threshold of the new logger.
Arc::Logger::~Logger ( )

Destroys a logger.

Member Function Documentation

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.

See addDestination(LogDestination& destination).

void Arc::Logger::deleteDestinations ( void  )

Remove all LogDestinations and delete LogDestination objects.

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 Logger& Arc::Logger::getRootLogger ( )
static

The root Logger.

This is the root Logger. It is an ancestor of any other Logger and always exists.

LogLevel Arc::Logger::getThreshold ( ) const

Returns the threshold of this logger.

void Arc::Logger::msg ( LogMessage  message)

Sends a LogMessage.

Parameters
messageThe LogMessage to send.
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() methods. It is also possible to use msg() with multiple arguments and printf-style string formatting, for example

logger.msg(INFO, "Operation no %i failed: %s", number, reason);
Parameters
levelThe level of the message.
strThe message text.
void Arc::Logger::removeDestinations ( void  )

Removes all LogDestinations.

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)

Sets the logging threshold.

This method sets the threshold of the Logger. Any message sent to this Logger that has a level below this threshold will be discarded.

Parameters
thresholdThe threshold
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.

Parameters
thresholdThe threshold
subdomainsThe subdomains of all loggers in chain
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.

Parameters
thresholdThe threshold
domainThe domain of logger

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