Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
dynamicgraph::Logger Class Reference

Class for logging messages. More...

#include <logger.h>

Public Member Functions

void countdown ()
 
double getStreamPrintPeriod ()
 
double getTimeSample ()
 
LoggerVerbosity getVerbosity ()
 
 Logger (double timeSample=0.001, double streamPrintPeriod=1.0)
 
void sendMsg (std::string msg, MsgType type, const std::string &lineId="")
 
void sendMsg (std::string msg, MsgType type, const std::string &file, int line)
 
bool setStreamPrintPeriod (double s)
 
bool setTimeSample (double t)
 
void setVerbosity (LoggerVerbosity lv)
 
RTLoggerStream stream ()
 
RTLoggerStream stream (MsgType type, const std::string &lineId="")
 
 ~Logger ()
 

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 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 More...
 
StreamCounterMap_t m_stream_msg_counters
 
double m_streamPrintPeriod
 specify the period of call of the countdown method More...
 
double m_timeSample
 verbosity of the logger 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.

Definition at line 186 of file logger.h.

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

Definition at line 261 of file logger.h.

Constructor & Destructor Documentation

◆ Logger()

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

Constructor

Definition at line 25 of file logger.cpp.

◆ ~Logger()

dynamicgraph::Logger::~Logger ( )

Destructor

Definition at line 32 of file logger.cpp.

Member Function Documentation

◆ acceptMsg()

bool dynamicgraph::Logger::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 272 of file logger.h.

◆ 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.

Definition at line 69 of file logger.cpp.

◆ countdown()

void dynamicgraph::Logger::countdown ( )

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

Definition at line 37 of file logger.cpp.

◆ getStreamPrintPeriod()

double dynamicgraph::Logger::getStreamPrintPeriod ( )

Get the time period for printing of streaming messages.

Definition at line 67 of file logger.cpp.

◆ getTimeSample()

double dynamicgraph::Logger::getTimeSample ( )

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

Definition at line 65 of file logger.cpp.

◆ getVerbosity()

LoggerVerbosity dynamicgraph::Logger::getVerbosity ( )

Get the verbosity level of the logger.

Definition at line 36 of file logger.cpp.

◆ isStreamMsg()

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

Definition at line 266 of file logger.h.

◆ sendMsg() [1/2]

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

Definition at line 42 of file logger.cpp.

◆ 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';

Definition at line 46 of file logger.cpp.

◆ setStreamPrintPeriod()

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

Set the time period for printing of streaming messages.

Definition at line 59 of file logger.cpp.

◆ setTimeSample()

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

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

Definition at line 53 of file logger.cpp.

◆ setVerbosity()

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

Set the verbosity level of the logger.

Definition at line 34 of file logger.cpp.

◆ stream() [1/2]

RTLoggerStream dynamicgraph::Logger::stream ( )
inline

Get an output stream independently of the debug level.

Definition at line 200 of file logger.h.

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

Definition at line 211 of file logger.h.

Member Data Documentation

◆ m_lv

LoggerVerbosity dynamicgraph::Logger::m_lv
protected

Definition at line 254 of file logger.h.

◆ m_printCountdown

double dynamicgraph::Logger::m_printCountdown
protected

specify the time period of the stream prints

Definition at line 258 of file logger.h.

◆ 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

Definition at line 264 of file logger.h.

◆ m_streamPrintPeriod

double dynamicgraph::Logger::m_streamPrintPeriod
protected

specify the period of call of the countdown method

Definition at line 257 of file logger.h.

◆ m_timeSample

double dynamicgraph::Logger::m_timeSample
protected

verbosity of the logger

Definition at line 255 of file logger.h.


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


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03