dynamic-graph  4.1.0-8-gdab7-dirty
Dynamic graph library
Logger Class Reference

Class for logging messages. More...

#include <dynamic-graph/logger.h>

Public Member Functions

 Logger (double timeSample=0.001, double streamPrintPeriod=1.0)
 
 ~Logger ()
 
void countdown ()
 
double getStreamPrintPeriod ()
 
double getTimeSample ()
 
LoggerVerbosity getVerbosity ()
 
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 setStreamPrintPeriod (double s)
 
bool setTimeSample (double t)
 
void setVerbosity (LoggerVerbosity lv)
 
RTLoggerStream stream ()
 
RTLoggerStream stream (MsgType type, const std::string &lineId="")
 

Protected Types

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

Protected Member Functions

bool acceptMsg (MsgType m, const std::string &lineId)
 
bool checkStreamPeriod (const std::string &lineId)
 
bool isStreamMsg (MsgType m)
 

Protected Attributes

LoggerVerbosity m_lv
 
double m_printCountdown
 specify the time period of the stream prints
 
StreamCounterMap_t m_stream_msg_counters
 
double m_streamPrintPeriod
 specify the period of call of the countdown method
 
double m_timeSample
 verbosity of the logger
 

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);
dgADD_OSTREAM_TO_RTLOG (of);
}
// Somewhere in your library
dynamicgraph::LoggerVerbosity aLoggerVerbosityLevel =
VERBOSITY_WARNING_ERROR;
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.

Definition at line 187 of file logger.h.

Constructor & Destructor Documentation

◆ Logger()

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

Constructor

◆ ~Logger()

~Logger ( )

Destructor

Member Function Documentation

◆ acceptMsg()

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

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

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

Definition at line 273 of file logger.h.

◆ checkStreamPeriod()

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

Check whether a message from lineId should be accepted.

Note
The internal counter associated to lineId is updated.

◆ countdown()

void countdown ( )

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

◆ getStreamPrintPeriod()

double getStreamPrintPeriod ( )

Get the time period for printing of streaming messages.

◆ getTimeSample()

double getTimeSample ( )

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

◆ getVerbosity()

LoggerVerbosity getVerbosity ( )

Get the verbosity level of the logger.

◆ sendMsg() [1/2]

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

◆ sendMsg() [2/2]

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

◆ setStreamPrintPeriod()

bool setStreamPrintPeriod ( double  s)

Set the time period for printing of streaming messages.

◆ setTimeSample()

bool setTimeSample ( double  t)

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

◆ setVerbosity()

void setVerbosity ( LoggerVerbosity  lv)

Set the verbosity level of the logger.

◆ stream() [1/2]

RTLoggerStream stream ( )
inline

Get an output stream independently of the debug level.

Definition at line 201 of file logger.h.

◆ stream() [2/2]

RTLoggerStream 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
typespecifies the verbosity level, for instance MSG_TYPE_DEBUG
lineIdtypically FILE ":" BOOST_PP_STRINGIZE(LINE)

Definition at line 212 of file logger.h.

Member Data Documentation

◆ m_stream_msg_counters

StreamCounterMap_t m_stream_msg_counters
protected

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

Definition at line 265 of file logger.h.


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