shark::Logger Class Reference

Implements a generic logging facility. More...

#include <shark/Core/Logger.h>

+ Collaboration diagram for shark::Logger:

Classes

class  AbstractFormatter
 Entrypoint for extending the logging framework with custom format handlers. More...
 
class  AbstractHandler
 Entrypoint for extending the logging framework with custom log handlers. More...
 
class  Record
 Models a single log record passed to the logging framework. More...
 

Public Types

enum  Level { DEBUG_LEVEL = 1, INFO_LEVEL = 2, WARNING_LEVEL = 4, ERROR_LEVEL = 8 }
 Models the different log levels known to the system. More...
 

Public Member Functions

 Logger ()
 
template<typename PropertyTree >
void configure (const PropertyTree &root)
 
void operator() (const Record &record)
 Processes the supplied record and passes it to the registered handlers. More...
 
Level logLevel () const
 Accesses the log level of this logger. More...
 
void setLogLevel (Level logLevel)
 Adjusts the log level of this logger. More...
 
void registerHandler (const boost::shared_ptr< AbstractHandler > &handler)
 Registers a handler instance with this logger. More...
 
void unregisterHandler (const boost::shared_ptr< AbstractHandler > &handler)
 Deregisters a handler instance from this logger. More...
 
bool hasHandler (const boost::shared_ptr< AbstractHandler > &handler) const
 Queries this logger instance if the handler is installed. More...
 

Static Public Member Functions

static const std::string & toString (Level level)
 Converts the supplied log level to a human-readable string representation. More...
 
static Level fromString (const std::string &level)
 Converts the supplied log level to an element of enumeration log level. More...
 

Static Public Attributes

static lut_type LEVEL_LUT
 Default look-up table for Level <-> string conversion. More...
 

Protected Attributes

Level m_logLevel
 Log level of the logger instance. More...
 
boost::unordered_set
< boost::shared_ptr
< AbstractHandler > > 
m_registeredHandlers
 Hash-set of registered handlers. More...
 
boost::mutex m_registeredHandlersGuard
 Guards the set of registered handlers. More...
 

Detailed Description

Implements a generic logging facility.

Simple logging mechanism and a singleton logger pool for logger management:

boost::shared_ptr<
> sharkLogger = shark::LoggerPool::instance().registerLogger( "edu.rub.ini.shark" );
sharkLogger << shark::Logger::Record( shark::Logger::INFO, "Info message.", "Test source" );

Definition at line 63 of file Logger.h.

Member Enumeration Documentation

Models the different log levels known to the system.

Enumerator
DEBUG_LEVEL 

Models debugging/tracing information.

INFO_LEVEL 

Models general information for reporting system states etc..

WARNING_LEVEL 

Models warning conditions.

ERROR_LEVEL 

Models actual errors.

Definition at line 74 of file Logger.h.

Constructor & Destructor Documentation

shark::Logger::Logger ( )
inline

Definition at line 298 of file Logger.h.

Member Function Documentation

template<typename PropertyTree >
void shark::Logger::configure ( const PropertyTree root)
inline

Definition at line 301 of file Logger.h.

References LEVEL_LUT, and m_logLevel.

static Level shark::Logger::fromString ( const std::string &  level)
inlinestatic

Converts the supplied log level to an element of enumeration log level.

Exceptions
shark::Exceptionif the log level is not known.

Definition at line 106 of file Logger.h.

References LEVEL_LUT, and SHARKEXCEPTION.

bool shark::Logger::hasHandler ( const boost::shared_ptr< AbstractHandler > &  handler) const
inline

Queries this logger instance if the handler is installed.

Definition at line 354 of file Logger.h.

References m_registeredHandlers.

Level shark::Logger::logLevel ( ) const
inline

Accesses the log level of this logger.

Definition at line 324 of file Logger.h.

References m_logLevel.

Referenced by operator()(), and setLogLevel().

void shark::Logger::operator() ( const Record record)
inline

Processes the supplied record and passes it to the registered handlers.

Definition at line 310 of file Logger.h.

References shark::Logger::Record::logLevel(), logLevel(), m_registeredHandlers, and m_registeredHandlersGuard.

void shark::Logger::registerHandler ( const boost::shared_ptr< AbstractHandler > &  handler)
inline

Registers a handler instance with this logger.

Definition at line 338 of file Logger.h.

References m_registeredHandlers, and m_registeredHandlersGuard.

void shark::Logger::setLogLevel ( Level  logLevel)
inline

Adjusts the log level of this logger.

Definition at line 331 of file Logger.h.

References logLevel(), and m_logLevel.

static const std::string& shark::Logger::toString ( Level  level)
inlinestatic

Converts the supplied log level to a human-readable string representation.

Exceptions
shark::Exceptionif log level is not known.

Definition at line 95 of file Logger.h.

References LEVEL_LUT, and SHARKEXCEPTION.

void shark::Logger::unregisterHandler ( const boost::shared_ptr< AbstractHandler > &  handler)
inline

Deregisters a handler instance from this logger.

Definition at line 346 of file Logger.h.

References m_registeredHandlers, and m_registeredHandlersGuard.

Member Data Documentation

Logger::lut_type shark::Logger::LEVEL_LUT
static
Initial value:
= boost::assign::list_of< Logger::lut_type::relation >
( Logger::DEBUG_LEVEL, "Debug" )
( Logger::INFO_LEVEL, "Info" )
( Logger::WARNING_LEVEL, "Warning" )
( Logger::ERROR_LEVEL, "Error" )

Default look-up table for Level <-> string conversion.

Definition at line 89 of file Logger.h.

Referenced by configure(), fromString(), and toString().

Level shark::Logger::m_logLevel
protected

Log level of the logger instance.

Definition at line 359 of file Logger.h.

Referenced by configure(), logLevel(), and setLogLevel().

boost::unordered_set< boost::shared_ptr< AbstractHandler > > shark::Logger::m_registeredHandlers
protected

Hash-set of registered handlers.

Definition at line 364 of file Logger.h.

Referenced by hasHandler(), operator()(), registerHandler(), and unregisterHandler().

boost::mutex shark::Logger::m_registeredHandlersGuard
protected

Guards the set of registered handlers.

Definition at line 365 of file Logger.h.

Referenced by operator()(), registerHandler(), and unregisterHandler().


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