Log Class Reference

#include <log.h>

Collaboration diagram for Log:

Collaboration graph
[legend]
List of all members.

Detailed Description

Logging wrapper providing shell for trace masks and strings.

Only static members are accessible and calls are forwarded to the only instance of this class, accessible via instance() member.

Definition at line 125 of file log.h.


Public Member Functions

void enableTraceMask (int traceInt, const std::string &traceStr)
 Enable a trace mask.
void enableTraceMask (const std::string &mask)
 Enable a string trace mask.
void addTraceMask (const std::string &mask)
 Add a string trace mask to supported list of string masks.
void disableTraceMask (int traceInt)
 Disable a trace mask.
void disableTraceMask (const std::string &mask)
 Disable a string trace mask.
void removeTraceMask (const std::string &mask)
 Erase a string trace mask from available string masks.
bool hasTraceMask (int traceMask)
 Check if a trace mask is enabled.
void addLogFile (const std::string &filename)
 Add a new log file target where all log messages will be written to.
void sendToFiles (std::string msg)
 Write specified string to all output streams.
void doLogString (MessageType t, const std::string &msg)
 Actual message logging.
void doLogString (int traceMask, const std::string &msg)
 Log a trace string only if the trace mask has been enabled.
void doLogString (const std::string &mask, const std::string &msg)
void addPreStr (const std::string &str)
 Add a string to prepend to all log messages.
void remPreStr (const std::string &str)
 Remove a string prepended to all log messages.
boost::signals::connection addHandler (boost::function< void(const std::string &, MessageType type)> ha)
 Add a handler function which will be passed all log messages which match the flags specified.
template<typename T>
boost::signals::connection addHandler (T *obj, void(T::*ha)(const std::string &, MessageType))
 More convenient version of the above function, performs function object binding internally.

Static Public Member Functions

static Loginstance ()
 Retrieve the only instance of this class.
static std::string getTraceStr (int traceMask)
 Retrieve string corresponding to a trace mask.
static void printLast (uint32_t count)
 Print last messages to std::cerr.
static std::string getLastMsg ()
 Retrieve the last logged message.
static void getLast (uint32_t count, std::vector< std::string > *cont)
 Retrieve last N messages.

Private Types

typedef std::vector< std::string
>::iterator 
FIter
 Iterator for the above list.
typedef std::deque< std::string
>::const_iterator 
CMIter
 Iterator typedef for the above list.
typedef std::map< int, std::string
>::iterator 
MIter
 For easier usaage.

Private Member Functions

 Log ()
 Constructor.
 Log (Log &)
 Forbidden.
Logoperator= (const Log &)
 Forbidden.
 ~Log ()
void addMsg (MessageType t, const std::string &msg)
 Adds messages to s_messages array.

Private Attributes

std::map< int, std::string > m_traceMasks
 Enabled trace masks.
std::set< std::string > m_strMasks
std::set< std::string > m_enabledStrMasks
std::vector< std::string > m_logFiles
 Output streams to write to.
boost::mutex m_filesLock
 Protects m_logFiles list and the streams contained within.
std::string m_preStr
 String to prepend to all log messages.
boost::signal< void(const
std::string &, MessageType)> 
m_sig

Static Private Attributes

static Logs_log = new Log
 Destructor Pointer to the single instance of this class.
static std::deque< std::string > s_messages
 Stores last N log messages (including trace and debug messages).
static boost::recursive_mutex s_iosLock
 Protects output streams for multiple thread access.

Friends

Various logging functions.
void DLLEXPORT logMsg (const std::string &msg)
 Log a simple message.
void DLLEXPORT logMsg (const boost::format &fmt)
 Log a formatted mesage.
void DLLEXPORT logDebug (const std::string &msg)
 Log a simple message only in debug mode.
void DLLEXPORT logDebug (const boost::format &fmt)
 Log a formatted message only in debug mode.
void DLLEXPORT logWarning (const std::string &msg)
 Log a warning (message will be prepended by "Warning:".
void DLLEXPORT logWarning (const boost::format &fmt)
 Log a formatted warning (message will be prepended by "Warning:".
void DLLEXPORT logError (const std::string &msg)
 Log an error (message will be prepended by "Error:").
void DLLEXPORT logError (const boost::format &fmt)
 Log a formatted error message (message will be prepended by "Error:").
void DLLEXPORT logFatalError (const std::string &msg)
 Log a fatal error and abort the application.
void DLLEXPORT logFatalError (const boost::format &msg)
 Log a fatal error and abort the application.
void DLLEXPORT logTrace (uint32_t mask, const std::string &msg)
void DLLEXPORT logTrace (uint32_t mask, const boost::format &msg)
void DLLEXPORT logTrace (const std::string &mask, const std::string &msg)
void DLLEXPORT logTrace (const std::string &mask, const boost::format &msg)

Member Typedef Documentation

typedef std::deque<std::string>::const_iterator Log::CMIter [private]
 

Iterator typedef for the above list.

Definition at line 389 of file log.h.

typedef std::vector<std::string>::iterator Log::FIter [private]
 

Iterator for the above list.

Definition at line 380 of file log.h.

typedef std::map<int, std::string>::iterator Log::MIter [private]
 

For easier usaage.

Definition at line 392 of file log.h.


Constructor & Destructor Documentation

Log::Log  )  [private]
 

Constructor.

Definition at line 30 of file log.cpp.

Log::Log Log  )  [private]
 

Forbidden.

Log::~Log  )  [private]
 

Definition at line 32 of file log.cpp.

References s_log.


Member Function Documentation

template<typename T>
boost::signals::connection Log::addHandler T *  obj,
void(T::*)(const std::string &, MessageType ha
[inline]
 

More convenient version of the above function, performs function object binding internally.

Definition at line 346 of file log.h.

boost::signals::connection Log::addHandler boost::function< void(const std::string &, MessageType type)>  ha  )  [inline]
 

Add a handler function which will be passed all log messages which match the flags specified.

Parameters:
h Function object taking const std::string& argument
flags Types of log messages to be passed to the handler. This is a bit-field containing one or more MessageType enumeration values. Example: addHandler(LOG_HANDLER(&MyClass::onLogMsg), MT_ERROR|MT_WARNING);

Definition at line 335 of file log.h.

void Log::addLogFile const std::string &  filename  )  [inline]
 

Add a new log file target where all log messages will be written to.

Parameters:
filename Path to log file.

Definition at line 230 of file log.h.

Referenced by HydraNode::initLog().

void Log::addMsg MessageType  t,
const std::string &  msg
[inline, private]
 

Adds messages to s_messages array.

Definition at line 363 of file log.h.

References s_messages.

Referenced by doLogString().

void Log::addPreStr const std::string &  str  )  [inline]
 

Add a string to prepend to all log messages.

String to prepend to log messages.

Definition at line 308 of file log.h.

Referenced by Detail::Initializer< T >::doExit(), HydraNode::init(), ModManager::loadModule(), ModManager::onExit(), and ModManager::onInit().

void Log::addTraceMask const std::string &  mask  )  [inline]
 

Add a string trace mask to supported list of string masks.

The mask can later be enabled using enableTraceMask() function.

Parameters:
mask Mask to be added.
Note:
This function is used to 'publish' the availability of a trace mask for others (e.g. user interfaces et al).

Definition at line 161 of file log.h.

void Log::disableTraceMask const std::string &  mask  )  [inline]
 

Disable a string trace mask.

Parameters:
mask Mask to be disabled.

Definition at line 180 of file log.h.

void Log::disableTraceMask int  traceInt  )  [inline]
 

Disable a trace mask.

Messages with this mask will no longer be shown.

Parameters:
traceInt Integer value of the traceMask to be removed.

Definition at line 171 of file log.h.

void Log::doLogString const std::string &  mask,
const std::string &  msg
[inline]
 

Definition at line 266 of file log.h.

References MT_TRACE.

void Log::doLogString int  traceMask,
const std::string &  msg
[inline]
 

Log a trace string only if the trace mask has been enabled.

Definition at line 253 of file log.h.

References getTraceStr(), hasTraceMask(), and MT_TRACE.

Here is the call graph for this function:

void Log::doLogString MessageType  t,
const std::string &  msg
 

Actual message logging.

Definition at line 85 of file log.cpp.

References addMsg(), m_preStr, and sendToFiles().

Referenced by logDebug(), logError(), logMsg(), logTrace(), and logWarning().

Here is the call graph for this function:

void Log::enableTraceMask const std::string &  mask  )  [inline]
 

Enable a string trace mask.

logTrace() calls using this mask will now be displayed.

Parameters:
mask String mask to enable.

Definition at line 148 of file log.h.

void Log::enableTraceMask int  traceInt,
const std::string &  traceStr
[inline]
 

Enable a trace mask.

Parameters:
traceInt Integer value. logTrace() calls with this value will now be enabled.
traceStr String for the trace messages - will be included in the log messages.

Definition at line 138 of file log.h.

void Log::getLast uint32_t  count,
std::vector< std::string > *  cont
[static]
 

Retrieve last N messages.

Parameters:
count Number of messages to retrieve.
cont Container to push the messages.

Definition at line 74 of file log.cpp.

References CHECK, and s_messages.

static std::string Log::getLastMsg  )  [inline, static]
 

Retrieve the last logged message.

Returns:
Last logged message.

Definition at line 291 of file log.h.

static std::string Log::getTraceStr int  traceMask  )  [inline, static]
 

Retrieve string corresponding to a trace mask.

Parameters:
traceMask Mask for which to look up the string
Returns:
String corresponding to the trace mask

Definition at line 216 of file log.h.

Referenced by doLogString().

bool Log::hasTraceMask int  traceMask  )  [inline]
 

Check if a trace mask is enabled.

Parameters:
traceMask Mask to be checked
Returns:
True if the mask is currently enabled

Definition at line 202 of file log.h.

Referenced by doLogString().

Log & Log::instance  )  [static]
 

Retrieve the only instance of this class.

Definition at line 35 of file log.cpp.

References s_log.

Referenced by Detail::Initializer< T >::doExit(), HydraNode::init(), HydraNode::initLog(), ModManager::loadModule(), logDebug(), logError(), logMsg(), logTrace(), logWarning(), ModManager::onExit(), and ModManager::onInit().

Log& Log::operator= const Log  )  [private]
 

Forbidden.

void Log::printLast uint32_t  count  )  [static]
 

Print last messages to std::cerr.

Parameters:
count Number of last messages to print.

Definition at line 62 of file log.cpp.

References s_messages.

Referenced by on_fatal_exception(), and on_terminate().

void Log::removeTraceMask const std::string &  mask  )  [inline]
 

Erase a string trace mask from available string masks.

Parameters:
mask Mask to be removed.
Note:
This also disables the mask.

Definition at line 191 of file log.h.

void Log::remPreStr const std::string &  str  )  [inline]
 

Remove a string prepended to all log messages.

Parameters:
str String to be removed.

Definition at line 317 of file log.h.

Referenced by Detail::Initializer< T >::doExit(), HydraNode::init(), ModManager::loadModule(), ModManager::onExit(), and ModManager::onInit().

void Log::sendToFiles std::string  msg  ) 
 

Write specified string to all output streams.

Parameters:
msg String to write.
Note:
msg is passed by value instead of reference since this function clears up any escaped symbols (e.g. colors) from the message.

Definition at line 39 of file log.cpp.

References m_filesLock, and m_logFiles.

Referenced by doLogString().


Friends And Related Function Documentation

void DLLEXPORT logDebug const boost::format &  fmt  )  [friend]
 

Log a formatted message only in debug mode.

Parameters:
fmt Format object to be logged

Definition at line 137 of file log.cpp.

void DLLEXPORT logDebug const std::string &  msg  )  [friend]
 

Log a simple message only in debug mode.

Parameters:
msg Message to be logged

Definition at line 122 of file log.cpp.

void DLLEXPORT logError const boost::format &  fmt  )  [friend]
 

Log a formatted error message (message will be prepended by "Error:").

Parameters:
fmt Formatted message to be logged

Definition at line 185 of file log.cpp.

void DLLEXPORT logError const std::string &  msg  )  [friend]
 

Log an error (message will be prepended by "Error:").

Parameters:
msg Message to be logged

Definition at line 173 of file log.cpp.

void DLLEXPORT logFatalError const boost::format &  msg  )  [friend]
 

Log a fatal error and abort the application.

Parameters:
fmt Formatted message to be logged

Definition at line 205 of file log.cpp.

void DLLEXPORT logFatalError const std::string &  msg  )  [friend]
 

Log a fatal error and abort the application.

Parameters:
msg Message to be logged

Definition at line 195 of file log.cpp.

void DLLEXPORT logMsg const boost::format &  fmt  )  [friend]
 

Log a formatted mesage.

Parameters:
fmt Format object to be logged

Definition at line 112 of file log.cpp.

void DLLEXPORT logMsg const std::string &  msg  )  [friend]
 

Log a simple message.

Parameters:
msg Message to be logged

Definition at line 102 of file log.cpp.

void DLLEXPORT logTrace const std::string &  mask,
const boost::format &  msg
[friend]
 

Definition at line 220 of file log.cpp.

void DLLEXPORT logTrace const std::string &  mask,
const std::string &  msg
[friend]
 

Definition at line 217 of file log.cpp.

void DLLEXPORT logTrace uint32_t  mask,
const boost::format &  msg
[friend]
 

Definition at line 211 of file log.cpp.

void DLLEXPORT logTrace uint32_t  mask,
const std::string &  msg
[friend]
 

Definition at line 214 of file log.cpp.

void DLLEXPORT logWarning const boost::format &  fmt  )  [friend]
 

Log a formatted warning (message will be prepended by "Warning:".

Parameters:
fmt Formatted message to be logged

Definition at line 163 of file log.cpp.

void DLLEXPORT logWarning const std::string &  msg  )  [friend]
 

Log a warning (message will be prepended by "Warning:".

Parameters:
msg Message to be logged

Definition at line 151 of file log.cpp.


Member Data Documentation

std::set<std::string> Log::m_enabledStrMasks [private]
 

Definition at line 374 of file log.h.

boost::mutex Log::m_filesLock [private]
 

Protects m_logFiles list and the streams contained within.

Definition at line 383 of file log.h.

Referenced by sendToFiles().

std::vector<std::string> Log::m_logFiles [private]
 

Output streams to write to.

Definition at line 377 of file log.h.

Referenced by sendToFiles().

std::string Log::m_preStr [private]
 

String to prepend to all log messages.

Definition at line 395 of file log.h.

Referenced by doLogString().

boost::signal<void (const std::string&, MessageType)> Log::m_sig [private]
 

Definition at line 428 of file log.h.

std::set<std::string> Log::m_strMasks [private]
 

Definition at line 373 of file log.h.

std::map<int, std::string> Log::m_traceMasks [private]
 

Enabled trace masks.

Definition at line 372 of file log.h.

boost::recursive_mutex Log::s_iosLock [static, private]
 

Protects output streams for multiple thread access.

Definition at line 26 of file log.cpp.

Log * Log::s_log = new Log [static, private]
 

Destructor Pointer to the single instance of this class.

Definition at line 27 of file log.cpp.

Referenced by instance(), and ~Log().

std::deque< std::string > Log::s_messages [static, private]
 

Stores last N log messages (including trace and debug messages).

Definition at line 28 of file log.cpp.

Referenced by addMsg(), getLast(), and printLast().


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