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...
 
RTLoggerStream stream ()
 Get an output stream independently of the debug level. More...
 
RTLoggerStream stream (MsgType type, const std::string &lineId="")
 Print the specified message on standard output if the verbosity level allows it. More...
 
void sendMsg (std::string msg, MsgType type, const std::string &lineId="")
 
void sendMsg (std::string msg, MsgType type, const std::string &file, int line) DYNAMIC_GRAPH_DEPRECATED
 
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 Types

typedef std::map< std::string, double > StreamCounterMap_t
 every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff More...
 

Protected Member Functions

bool isStreamMsg (MsgType m)
 
bool acceptMsg (MsgType m, const std::string &lineId)
 Check whether a message of type and from lineId should be accepted. More...
 
bool checkStreamPeriod (const std::string &lineId)
 Check whether a message from lineId should be accepted. More...
 

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...
 
StreamCounterMap_t m_stream_msg_counters
 Pointer to the dynamic structure which holds the collection of streaming messages. More...
 

Detailed Description

Class for logging messages.

It is intended to be used like this:

#define ENABLE_RT_LOG
// 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
dynamicgraph::LoggerVerbosity aLoggerVerbosityLevel =
entity.setLoggerVerbosityLevel(aLoggerVerbosityLevel);
...
// using macros
DYNAMIC_GRAPH_ENTITY_WARNING(entity) << "your message\n";
// or the equivalent code without macros:
// Please use '\n' instead of std::endl and flushing will have no effect
entity.logger.stream(dynamicgraph::MSG_TYPE_WARNING,
__FILE__ BOOST_PP_STRINGIZE(__LINE__))
<< your message << '\n';
Todo:
remove m_timeSample and streamPrintPeriod to rather use a simple integer counting the number of calls. This will achieve exactly the same behaviour without rouding numerical errors.

Member Typedef Documentation

◆ StreamCounterMap_t

typedef std::map<std::string, double> dynamicgraph::Logger::StreamCounterMap_t
protected

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

Constructor & Destructor Documentation

◆ Logger()

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

Constructor.

◆ ~Logger()

dynamicgraph::Logger::~Logger ( )

Destructor.

Member Function Documentation

◆ acceptMsg()

bool dynamicgraph::Logger::acceptMsg ( MsgType  m,
const std::string &  lineId 
)
inlineprotected

Check whether a message of type and from lineId should be accepted.

Note
If is a stream type, the internal counter associated to lineId is updated.

References checkStreamPeriod(), isStreamMsg(), and dynamicgraph::MSG_TYPE_TYPE_BITS.

Referenced by stream().

◆ checkStreamPeriod()

bool dynamicgraph::Logger::checkStreamPeriod ( const std::string &  lineId)
protected

Check whether a message from lineId should be accepted.

Note
The internal counter associated to lineId is updated.

Referenced by acceptMsg().

◆ countdown()

void dynamicgraph::Logger::countdown ( )

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

◆ getStreamPrintPeriod()

double dynamicgraph::Logger::getStreamPrintPeriod ( )

Get the time period for printing of streaming messages.

Referenced by stream().

◆ getTimeSample()

double dynamicgraph::Logger::getTimeSample ( )

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

Referenced by stream().

◆ getVerbosity()

LoggerVerbosity dynamicgraph::Logger::getVerbosity ( )

Get the verbosity level of the logger.

Referenced by stream().

◆ isStreamMsg()

bool dynamicgraph::Logger::isStreamMsg ( MsgType  m)
inlineprotected

References dynamicgraph::MSG_TYPE_STREAM_BIT.

Referenced by acceptMsg().

◆ sendMsg() [1/2]

void dynamicgraph::Logger::sendMsg ( std::string  msg,
MsgType  type,
const std::string &  lineId = "" 
)
Deprecated:
instead, use
stream(type, lineId) << msg << '\n';

Referenced by stream().

◆ sendMsg() [2/2]

void dynamicgraph::Logger::sendMsg ( std::string  msg,
MsgType  type,
const std::string &  file,
int  line 
)
Deprecated:
instead, use
stream(type, lineId) << msg << '\n';

◆ setStreamPrintPeriod()

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

Set the time period for printing of streaming messages.

Referenced by stream().

◆ setTimeSample()

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

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

Referenced by stream().

◆ setVerbosity()

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

Set the verbosity level of the logger.

Referenced by stream().

◆ stream() [1/2]

RTLoggerStream dynamicgraph::Logger::stream ( )
inline

Get an output stream independently of the debug level.

◆ stream() [2/2]

RTLoggerStream dynamicgraph::Logger::stream ( MsgType  type,
const std::string &  lineId = "" 
)
inline

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

The lineId is used to identify the point where sendMsg is called so that streaming messages are printed only every streamPrintPeriod iterations.

Parameters
lineIdtypically __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__)

References acceptMsg(), DYNAMIC_GRAPH_DEPRECATED, dynamicgraph::RealTimeLogger::emptyStream(), dynamicgraph::RealTimeLogger::front(), getStreamPrintPeriod(), getTimeSample(), getVerbosity(), dynamicgraph::RealTimeLogger::instance(), sendMsg(), setStreamPrintPeriod(), setTimeSample(), and setVerbosity().

Member Data Documentation

◆ m_lv

LoggerVerbosity dynamicgraph::Logger::m_lv
protected

◆ m_printCountdown

double dynamicgraph::Logger::m_printCountdown
protected

specify the time period of the stream prints

◆ m_stream_msg_counters

StreamCounterMap_t dynamicgraph::Logger::m_stream_msg_counters
protected

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

◆ m_streamPrintPeriod

double dynamicgraph::Logger::m_streamPrintPeriod
protected

specify the period of call of the countdown method

◆ m_timeSample

double dynamicgraph::Logger::m_timeSample
protected

verbosity of the logger