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
double m_streamPrintPeriod
specify the period of call of the countdown method
Definition: logger.h:257
RTLoggerStream stream()
Definition: logger.h:200
double getTimeSample()
Definition: logger.cpp:65
bool checkStreamPeriod(const std::string &lineId)
Definition: logger.cpp:69
double m_timeSample
verbosity of the logger
Definition: logger.h:255
double getStreamPrintPeriod()
Definition: logger.cpp:67
Logger(double timeSample=0.001, double streamPrintPeriod=1.0)
Definition: logger.cpp:25
bool setTimeSample(double t)
Definition: logger.cpp:53
void setVerbosity(LoggerVerbosity lv)
Definition: logger.cpp:34
LoggerVerbosity m_lv
Definition: logger.h:254
bool setStreamPrintPeriod(double s)
Definition: logger.cpp:59
double m_printCountdown
specify the time period of the stream prints
Definition: logger.h:258
void sendMsg(std::string msg, MsgType type, const std::string &lineId="")
Definition: logger.cpp:42
StreamCounterMap_t m_stream_msg_counters
Definition: logger.h:264
LoggerVerbosity getVerbosity()
Definition: logger.cpp:36


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