All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamicgraph::Logger Class Reference

Class for logging messages. More...

#include <dynamic-graph/logger.h>

Collaboration diagram for dynamicgraph::Logger:
[legend]

Public Member Functions

 Logger (double timeSample=0.001, double streamPrintPeriod=1.0)
 Constructor. More...
 
 ~Logger ()
 Destructor. More...
 
void countdown ()
 Method to be called at every control iteration to decrement the internal Logger's counter. More...
 
void sendMsg (std::string msg, MsgType type, const char *file="", int line=0)
 Print the specified message on standard output if the verbosity level allows it. More...
 
bool setTimeSample (double t)
 Set the sampling time at which the method countdown() is going to be called. More...
 
double getTimeSample ()
 Get the sampling time at which the method countdown() is going to be called. More...
 
bool setStreamPrintPeriod (double s)
 Set the time period for printing of streaming messages. More...
 
double getStreamPrintPeriod ()
 Get the time period for printing of streaming messages. More...
 
void setVerbosity (LoggerVerbosity lv)
 Set the verbosity level of the logger. More...
 
LoggerVerbosity getVerbosity ()
 Get the verbosity level of the logger. More...
 

Protected Member Functions

bool isStreamMsg (MsgType m)
 
bool isDebugMsg (MsgType m)
 
bool isInfoMsg (MsgType m)
 
bool isWarningMsg (MsgType m)
 
bool isErrorMsg (MsgType m)
 

Protected Attributes

LoggerVerbosity m_lv
 
double m_timeSample
 verbosity of the logger More...
 
double m_streamPrintPeriod
 specify the period of call of the countdown method More...
 
double m_printCountdown
 specify the time period of the stream prints More...
 
std::map< std::string, double > m_stream_msg_counters
 every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff More...
 

Detailed Description

Class for logging messages.

It is intended to be used like this:

* #define ENABLE_RT_LOG
* #include <dynamic-graph/real-time-logger.h>
*
* // Somewhere in the main function of your executable
* int main (int argc, char** argv) {
* std::ofstream of;
* of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app);
* }
*
* // Somewhere in your library
* entity.setLoggerVerbosityLevel(aLoggerVerbosityLevel);
* ...
* std::string aMsg=aBaseMsg+" WARNING";
* entity.sendMsg(aMsg,dynamicgraph::MSG_TYPE_WARNING, __FILE__,__LINE__);
*
*

Constructor & Destructor Documentation

dynamicgraph::Logger::Logger ( double  timeSample = 0.001,
double  streamPrintPeriod = 1.0 
)

Constructor.

dynamicgraph::Logger::~Logger ( )

Destructor.

Member Function Documentation

void dynamicgraph::Logger::countdown ( )

Method to be called at every control iteration to decrement the internal Logger's counter.

double dynamicgraph::Logger::getStreamPrintPeriod ( )

Get the time period for printing of streaming messages.

double dynamicgraph::Logger::getTimeSample ( )

Get the sampling time at which the method countdown() is going to be called.

LoggerVerbosity dynamicgraph::Logger::getVerbosity ( )

Get the verbosity level of the logger.

bool dynamicgraph::Logger::isDebugMsg ( MsgType  m)
inlineprotected
bool dynamicgraph::Logger::isErrorMsg ( MsgType  m)
inlineprotected
bool dynamicgraph::Logger::isInfoMsg ( MsgType  m)
inlineprotected
bool dynamicgraph::Logger::isWarningMsg ( MsgType  m)
inlineprotected
void dynamicgraph::Logger::sendMsg ( std::string  msg,
MsgType  type,
const char *  file = "",
int  line = 0 
)

Print the specified message on standard output if the verbosity level allows it.

The file name and the line number are used to identify the point where sendMsg is called so that streaming messages are printed only every streamPrintPeriod iterations.

bool dynamicgraph::Logger::setStreamPrintPeriod ( double  s)

Set the time period for printing of streaming messages.

bool dynamicgraph::Logger::setTimeSample ( double  t)

Set the sampling time at which the method countdown() is going to be called.

void dynamicgraph::Logger::setVerbosity ( LoggerVerbosity  lv)

Set the verbosity level of the logger.

Member Data Documentation

LoggerVerbosity dynamicgraph::Logger::m_lv
protected
double dynamicgraph::Logger::m_printCountdown
protected

specify the time period of the stream prints

std::map<std::string, double> dynamicgraph::Logger::m_stream_msg_counters
protected

every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff

Pointer to the dynamic structure which holds the collection of streaming messages

double dynamicgraph::Logger::m_streamPrintPeriod
protected

specify the period of call of the countdown method

double dynamicgraph::Logger::m_timeSample
protected

verbosity of the logger