logger.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015, 2019
3  * LAAS-CNRS
4  * Andrea Del Prete, François Bailly, Olivier Stasse
5  *
6  */
7 
8 #ifndef WIN32
9 #include <sys/time.h>
10 #else
11 #include <Windows.h>
12 #endif
13 #define ENABLE_RT_LOG
14 
15 #include <dynamic-graph/logger.h>
17 #include <stdio.h>
18 
19 #include <iomanip> // std::setprecision
20 #include <iostream>
21 #include <sstream>
22 
23 namespace dynamicgraph {
24 
25 Logger::Logger(double timeSample, double streamPrintPeriod)
26  : m_timeSample(timeSample),
27  m_streamPrintPeriod(streamPrintPeriod),
28  m_printCountdown(0.0) {
30 }
31 
33 
35 
40 }
41 
42 void Logger::sendMsg(std::string msg, MsgType type, const std::string &lineId) {
43  stream(type, lineId) << msg << '\n';
44 }
45 
46 void Logger::sendMsg(std::string msg, MsgType type, const std::string &file,
47  int line) {
48  std::ostringstream oss;
49  oss << file << line;
50  stream(type, oss.str()) << msg << '\n';
51 }
52 
53 bool Logger::setTimeSample(double t) {
54  if (t <= 0.0) return false;
55  m_timeSample = t;
56  return true;
57 }
58 
60  if (s <= 0.0) return false;
62  return true;
63 }
64 
65 double Logger::getTimeSample() { return m_timeSample; }
66 
68 
69 bool Logger::checkStreamPeriod(const std::string &lineId) {
70  // insert element with value 0 if it does not exist.
71  // otherwise, return a counter to the existing one.
72  std::pair<StreamCounterMap_t::iterator, bool> result =
73  m_stream_msg_counters.insert(std::make_pair(lineId, 0.));
74 
75  // if counter is greater than 0 then decrement it and do not print
76  double &counter = result.first->second;
77  counter -= m_timeSample;
78  if (counter > 0.0) {
79  return false;
80  } else // otherwise reset counter and print
81  counter = m_streamPrintPeriod;
82  return true;
83 }
84 
85 } // namespace dynamicgraph
dynamicgraph::Logger::m_stream_msg_counters
StreamCounterMap_t m_stream_msg_counters
Definition: logger.h:264
dynamicgraph::Logger::setTimeSample
bool setTimeSample(double t)
Definition: logger.cpp:53
dynamicgraph::Logger::countdown
void countdown()
Definition: logger.cpp:37
dynamicgraph::Logger::setStreamPrintPeriod
bool setStreamPrintPeriod(double s)
Definition: logger.cpp:59
dynamicgraph::Logger::getStreamPrintPeriod
double getStreamPrintPeriod()
Definition: logger.cpp:67
logger.h
dynamicgraph::LoggerVerbosity
LoggerVerbosity
Definition: logger.h:143
dynamicgraph::Logger::m_printCountdown
double m_printCountdown
specify the time period of the stream prints
Definition: logger.h:258
dynamicgraph
dynamicgraph::Logger::setVerbosity
void setVerbosity(LoggerVerbosity lv)
Definition: logger.cpp:34
dynamicgraph::Logger::m_lv
LoggerVerbosity m_lv
Definition: logger.h:254
dynamicgraph::Logger::~Logger
~Logger()
Definition: logger.cpp:32
dynamicgraph::Logger::m_streamPrintPeriod
double m_streamPrintPeriod
specify the period of call of the countdown method
Definition: logger.h:257
dynamicgraph::Logger::getVerbosity
LoggerVerbosity getVerbosity()
Definition: logger.cpp:36
dynamicgraph::MsgType
MsgType
Definition: logger.h:29
dynamicgraph::Logger::stream
RTLoggerStream stream()
Definition: logger.h:200
dynamicgraph::Logger::m_timeSample
double m_timeSample
verbosity of the logger
Definition: logger.h:255
dynamicgraph::VERBOSITY_ERROR
@ VERBOSITY_ERROR
Definition: logger.h:147
dynamicgraph::Logger::Logger
Logger(double timeSample=0.001, double streamPrintPeriod=1.0)
Definition: logger.cpp:25
real-time-logger.h
dynamicgraph::Logger::getTimeSample
double getTimeSample()
Definition: logger.cpp:65
dynamicgraph::Logger::checkStreamPeriod
bool checkStreamPeriod(const std::string &lineId)
Definition: logger.cpp:69
dynamicgraph::Logger::sendMsg
void sendMsg(std::string msg, MsgType type, const std::string &lineId="")
Definition: logger.cpp:42


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38