ork::Logger Class Reference
[core]

A logger to log messages. More...

#include <Logger.h>

Inheritance diagram for ork::Logger:
ork::Object ork::FileLogger

List of all members.

Public Member Functions

 Logger (const string &type)
 Creates a new logger of the given type (debug, info, warning, etc).
virtual ~Logger ()
 Destroys this logger.
void addTopic (const string &topic)
 Adds the given topic to the list of topics managed by this logger.
bool hasTopic (const string &topic)
 Returns true if messages of the given topic are logged by this logger.
virtual void log (const string &topic, const string &msg)
 Logs a message given by its topic and its content.
void logf (const char *topic, const char *fmt,...)
 Formatted logging for more usability.
virtual void flush ()
 Flushes the buffer of this logger, if any.

Static Public Attributes

static static_ptr< LoggerDEBUG_LOGGER
 The logger for debug messages.
static static_ptr< LoggerINFO_LOGGER
 The logger for information messages.
static static_ptr< LoggerWARNING_LOGGER
 The logger for warning messages.
static static_ptr< LoggerERROR_LOGGER
 The logger for error messages.

Protected Attributes

const string type
 The type of this logger (debug, info, warning, error, etc).
string topics
 The topics handled by this logger, separated by semi-columns.
void * mutex
 A mutex to access this logger from multiple threads.

Detailed Description

A logger to log messages.

Debug, info, warning and error messages must be logged to the static DEBUG_LOGGER, INFO_LOGGER, WARNING_LOGGER and ERROR_LOGGER. Each message has a topic. By default a logger logs all messages, whatever their topic, but it is possible to restrict logging to some topics only with addTopic.


Constructor & Destructor Documentation

ork::Logger::Logger ( const string &  type  ) 

Creates a new logger of the given type (debug, info, warning, etc).

virtual ork::Logger::~Logger (  )  [virtual]

Destroys this logger.


Member Function Documentation

void ork::Logger::addTopic ( const string &  topic  ) 

Adds the given topic to the list of topics managed by this logger.

By default a logger logs all messages, whatever their topic. But if at least one topic is selected by this method, only messages whose topic has been selected by this method will be logged.

virtual void ork::Logger::flush (  )  [virtual]

Flushes the buffer of this logger, if any.

Reimplemented in ork::FileLogger.

bool ork::Logger::hasTopic ( const string &  topic  ) 

Returns true if messages of the given topic are logged by this logger.

virtual void ork::Logger::log ( const string &  topic,
const string &  msg 
) [virtual]

Logs a message given by its topic and its content.

The default implementation of this method sends the message to the standard error output stream cerr.

Reimplemented in ork::FileLogger.

void ork::Logger::logf ( const char *  topic,
const char *  fmt,
  ... 
)

Formatted logging for more usability.

The problem is that Logger is not an ostream (or an ostringstream). I tried to derive ostream but it requires extra work. So here go C variadic functions. Must have a char * topic since std::string are not POD and this does not work with variable arguments list :| So it's really a compromise.


Member Data Documentation

The logger for debug messages.

The logger for error messages.

The logger for information messages.

void* ork::Logger::mutex [protected]

A mutex to access this logger from multiple threads.

string ork::Logger::topics [protected]

The topics handled by this logger, separated by semi-columns.

An empty string means that all topics are handled.

const string ork::Logger::type [protected]

The type of this logger (debug, info, warning, error, etc).

Reimplemented from ork::Object.

The logger for warning messages.


Generated on Mon Oct 18 09:36:07 2010 for ork by  doxygen 1.6.1