Main MRPT website > C++ reference for MRPT 1.9.9
system/COutputLogger.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
13 #include <mrpt/system/os.h> // for console color constants
14 #include <mrpt/system/CTicTac.h>
15 #include <mrpt/system/datetime.h> // TTimeStamp
16 
17 #include <string>
18 #include <deque>
19 #include <sstream>
20 #include <iosfwd>
21 #include <functional>
22 
23 namespace mrpt
24 {
25 namespace system
26 {
27 /** \brief Enumeration of available verbosity levels. \sa COutputLogger */
29 {
30  LVL_DEBUG = 0,
34  // ------------
36 };
37 
38 /** Callback types for use with mrpt::system::COuputLogger */
39 using output_logger_callback_t = std::function<void(
41  const std::string& loggerName, const mrpt::system::TTimeStamp timestamp)>;
42 
43 /** \brief Versatile class for consistent logging and
44  * management of output messages
45  *
46  * COutputLogger is a versatile class for logging messages either to the
47  * terminal window or to an external file. Class instances can take messages in
48  * std::string using the logStr class methods. The following macros are also
49  * provided
50  * for usage within a class that inherits from COutputLogger:
51  *
52  * \code
53  * // Plain strings:
54  * MRPT_LOG_DEBUG("This will be shown only if verbosity level is LVL_DEBUG.");
55  * MRPT_LOG_ERROR("This message will be always shown.");
56  * // printf-like versions:
57  * MRPT_LOG_ERROR_FMT("Out of range value: %i.", int_param);
58  * // stream-like versions:
59  * MRPT_LOG_ERROR_STREAM("Out of range value: " << int_param << " more vars: "
60  * << other_var);
61  * // Minimum period (in seconds) between messages:
62  * MRPT_LOG_THROTTLE_DEBUG_STREAM(5.0, "Var=" << value << " foo=" << foo_var);
63  * // Only once:
64  * MRPT_LOG_ONCE_WARN("Notice: blah blah");
65  * \endcode
66  *
67  * From outside of a class inheriting from COutputLogger the following
68  * `MRPT_UNSCOPED_{START|END}` macros are provided:
69  *
70  * \code
71  * MRPT_UNSCOPED_LOGGER_START;
72  * MRPT_LOG_WARN("blah");
73  * MRPT_LOG_ERROR_STREAM("error: " << strval);
74  * MRPT_UNSCOPED_LOGGER_END;
75  * \endcode
76  *
77  * - Logger instance keeps the messages in an internal container so that upon
78  * request it can dump them either to the console or to an external file
79  * altogether.
80  * - The message, when printed in the terminal window, is **colored** according
81  * to
82  * the logger's current verbosity/logging level (Logging level with which
83  * the underlying TMsg instance was instantiatedd). The available verbosity
84  * levels as well as their corresponding colors are listed below:
85  *
86  * + LVL_DEBUG => CONCOL_BLUE
87  * + LVL_INFO => CONCOL_NORMAL
88  * + LVL_WARN => CONCOL_GREEN
89  * + LVL_ERROR => CONCOL_RED
90  *
91  * - Logged messages are displayed in the screen if the current logger level is
92  * higher than m_min_verbosity_level (logger ignores those messages
93  * altogether). This can be used for filtering the output messages according
94  * to their importance (e.g. show only error messages by issuing
95  * setMinLoggingLevel(LVL_ERROR)).
96  * \sa setLoggingLevel, setMinLoggingLevel
97  *
98  * Default logging level is LVL_INFO.
99  *
100  * User may receive callbacks whenever a message is displayed to console by
101  * using
102  * logRegisterCallback(). If for some reason the callbacks are not needed any
103  * more,
104  * use logDeregisterCallback() to stop receiving calls. This mechanism is useful
105  * in case of showing the messages to a GUI, transmiting them to a remote
106  * machine, etc.
107  *
108  * \note By default every logged message is going to be dumped to the standard
109  * output as well (if VerbosityLevel > m_min_verbosity_level). Unset \b
110  * logging_enable_console_output class variable if that's not the desired
111  * behavior
112  *
113  * \note [New in MRPT 1.5.0]
114  * \sa TMsg
115  * \ingroup mrpt_system_grp
116  */
118 {
119  public:
120  /** Map from VerbosityLevels to their corresponding
121  * mrpt::system::TConsoleColor. Handy for coloring the input based on the
122  * verbosity of the message */
125 
126  /** Map from VerbosityLevels to their corresponding names. Handy for
127  * printing the current message VerbosityLevel along with the actual content
128  */
130 
131  /** @name Logging methods
132  * @{ */
133 
134  /**
135  * \brief Construct a COutputLogger instance with the given name as the
136  * instance name.
137  *
138  * Call to this constructor can be used instead of first initializing the
139  * object and then explicitly setting the name like in the following case:
140  * \code
141  * COutputLogger a_logger;
142  * a_logger.setLoggerName("logger_name");
143  * \endcode
144  */
146  /** Default class constructor. Name of the logger is initialized to "logStr"
147  */
148  COutputLogger();
149  /** virtual dtor (so we can derive classes from this one) */
150  virtual ~COutputLogger();
151 
152  /** \brief Main method to add the specified message string to the logger.
153  * \sa logCond, logFmt */
154  void logStr(const VerbosityLevel level, const std::string& msg_str)
155  const; // renamed from log() to avoid conflict with math ::log()
156 
157  /** \brief Alternative logging method, which mimics the printf behavior.
158  *
159  * Handy for not having to first use mrpt::format to pass a std::string
160  * message to logStr
161  *
162  * \code
163  * // instead of:
164  * logStr(mrpt::format("Today is the %d of %s, %d", 15, "July", 2016));
165  *
166  * // one can use:
167  * logFmt("Today is the %d of %s, %d", 15, "July", 2016);
168  * \endcode
169  *
170  * \sa logStr, logCond
171  */
172  void logFmt(const VerbosityLevel level, const char* fmt, ...) const
173  MRPT_printf_format_check(3, 4); // arg 1=this
174 
175  /** \brief Log the given message only if the condition is satisfied.
176  *
177  * \sa log, logFmt
178  */
179  void logCond(
180  const VerbosityLevel level, bool cond,
181  const std::string& msg_str) const;
182 
183  /** Set the name of the COutputLogger instance. \sa getLoggerName */
184  void setLoggerName(const std::string& name);
185  /** Return the name of the COutputLogger instance. \sa setLoggerName */
186  std::string getLoggerName() const;
187 
188  /** \brief Set the *minimum* logging level for which the incoming logs are
189  * going to be taken into account.
190  *
191  * String messages with specified VerbosityLevel smaller than the min, will
192  * not be outputted to the screen and neither will a record of them be
193  * stored in by the COutputLogger instance
194  */
196  /** alias of setMinLoggingLevel() */
198 
199  /** \sa setMinLoggingLevel */
202  {
203  return m_min_verbosity_level <= level;
204  }
205 
206  /** Fill the provided string with the contents of the logger's history in
207  * std::string representation */
208  void getLogAsString(std::string& log_contents) const;
209  /** Get the history of COutputLogger instance in a string representation. */
210  std::string getLogAsString() const;
211 
212  /** \brief Write the contents of the COutputLogger instance to an external
213  * file.
214  *
215  * Upon call to this method, COutputLogger dumps the contents of all the
216  * logged commands so far to the specified external file. By default the
217  * filename is set to ${LOGGERNAME}.log except if the fname parameter is
218  * provided
219  *
220  * \sa dumpToConsole, getAsString
221  */
222  void writeLogToFile(const std::string* fname_in = NULL) const;
223  /** \brief Dump the current contents of the COutputLogger instance in the
224  * terminal window.
225  *
226  * \sa writeToFile
227  */
228  void dumpLogToConsole() const;
229  /** Return the last Tmsg instance registered in the logger history */
231  /** Fill inputtted string with the contents of the last message in history
232  */
233  void getLoggerLastMsg(std::string& msg_str) const;
234  /** Reset the contents of the logger instance. Called upon construction. */
235  void loggerReset();
236 
237  /** [Default=true] Set it to false in case you don't want the logged
238  * messages to be dumped to the output automatically. */
240  /** [Default=false] Enables storing all messages into an internal list. \sa
241  * writeLogToFile, getLogAsString */
243 
245  /** \return true if an entry was found and deleted. */
247  /** @} */
248 
249  protected:
250  /** \brief Provided messages with VerbosityLevel smaller than this value
251  * shall be ignored */
253 
254  private:
255  /**
256  * \brief Struct responsible of holding information relevant to the message
257  * (in std::string form) issued by the user.
258  *
259  * Upon TMsg initialization, instance fetches the name of the caller
260  * COutputLogger, as well as the VerbosityLevel and the
261  * mrpt::system::TTimeStamp of the message provided.
262  * The format of the message when this is printed / or written to an
263  * external file complies is given below:
264  *
265  * <center><em> [name | level | timestamp:] body </em></center>
266  */
267  struct TMsg
268  {
269  /** \brief Class constructor that passes a message in std::string
270  * form as well as a reference to the COutputLogger that provided the
271  * current message
272  */
273  TMsg(
275  const COutputLogger& logger);
276  /** \brief Default Destructor */
277  ~TMsg();
278 
279  /** \brief Return a string representation of the underlying message */
280  std::string getAsString() const;
281  /** \brief Fill the string with the contents of the underlying message
282  * in
283  * string representation */
284  void getAsString(std::string* contents) const;
285  /** \brief Write the message contents to the specified stream
286  *
287  * \sa getAsString
288  */
289  void writeToStream(std::ostream& out) const;
290  /** \brief Dump the message contents to the standard output
291  *
292  * \sa writeToStream
293  */
294  void dumpToConsole() const;
295  /** \brief Reset the contents of the TMsg instance */
296  void reset();
297 
298  // parameters of the message under construction
299  mrpt::system::TTimeStamp timestamp; /**< Timestamp of the message. */
300  VerbosityLevel level; /**< Verbosity level of the message. */
301  std::string name; /**< Name of the COutputLogger instance that called
302  registered the message. */
303  std::string body; /**< Actual content of the message. */
304  };
305 
306  /** Helper method for generating a std::string instance from printf-like
307  * arguments */
308  std::string generateStringFromFormat(const char* fmt, va_list argp) const;
309 
311  mutable std::deque<TMsg>
312  m_history; // deque is better than vector to avoid memory reallocs
313 
314  std::deque<output_logger_callback_t> m_listCallbacks;
315 };
316 
317 /** For use in MRPT_LOG_DEBUG_STREAM(), etc. */
319 {
321  VerbosityLevel level, const COutputLogger& logger)
322  : m_level(level), m_logger(logger)
323  {
324  }
326  {
328  m_logger.logStr(m_level, m_str.str());
329  }
330 
331  template <typename T>
332  std::stringstream& operator<<(const T& val)
333  {
334  m_str << val;
335  return m_str;
336  }
337  // Overload for std::stringstream objects
338  std::stringstream& operator<<(const std::stringstream& val)
339  {
340  m_str << val.str();
341  return m_str;
342  }
343 
344  private:
345  std::stringstream m_str;
348 };
349 
350 #define INTERNAL_MRPT_LOG(_LVL, _STRING) this->logStr(_LVL, _STRING)
351 
352 #define INTERNAL_MRPT_LOG_ONCE(_LVL, _STRING) \
353  do \
354  { \
355  static once_flag = false; \
356  if (!once_flag) \
357  { \
358  once_flag = true; \
359  this->logStr(_LVL, _STRING); \
360  } \
361  } while (0)
362 
363 #define INTERNAL_MRPT_LOG_FMT(_LVL, _FMT_STRING, ...) \
364  do \
365  { \
366  if (this->isLoggingLevelVisible(_LVL)) \
367  { \
368  this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \
369  } \
370  } while (0)
371 
372 #define INTERNAL_MRPT_LOG_STREAM(_LVL, __CONTENTS) \
373  do \
374  { \
375  if (this->isLoggingLevelVisible(_LVL)) \
376  { \
377  ::mrpt::system::COutputLoggerStreamWrapper(_LVL, *this) \
378  << __CONTENTS; \
379  } \
380  } while (0)
381 
382 #define INTERNAL_MRPT_LOG_THROTTLE(_LVL, _PERIOD_SECONDS, _STRING) \
383  do \
384  { \
385  if (this->isLoggingLevelVisible(_LVL)) \
386  { \
387  static mrpt::system::CTicTac tim; \
388  if (tim.Tac() > _PERIOD_SECONDS) \
389  { \
390  tim.Tic(); \
391  this->logStr(_LVL, _STRING); \
392  } \
393  } \
394  } while (0)
395 
396 #define INTERNAL_MRPT_LOG_THROTTLE_STREAM(_LVL, _PERIOD_SECONDS, __CONTENTS) \
397  do \
398  { \
399  if (this->isLoggingLevelVisible(_LVL)) \
400  { \
401  static mrpt::system::CTicTac tim; \
402  if (tim.Tac() > _PERIOD_SECONDS) \
403  { \
404  tim.Tic(); \
405  ::mrpt::system::COutputLoggerStreamWrapper(_LVL, *this) \
406  << __CONTENTS; \
407  } \
408  } \
409  } while (0)
410 
411 #define INTERNAL_MRPT_LOG_THROTTLE_FMT( \
412  _LVL, _PERIOD_SECONDS, _FMT_STRING, ...) \
413  do \
414  { \
415  if (this->isLoggingLevelVisible(_LVL)) \
416  { \
417  static mrpt::system::CTicTac tim; \
418  if (tim.Tac() > _PERIOD_SECONDS) \
419  { \
420  tim.Tic(); \
421  this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \
422  } \
423  } \
424  } while (0)
425 
426 /** Use: `MRPT_LOG_DEBUG("message");` */
427 #define MRPT_LOG_DEBUG(_STRING) \
428  INTERNAL_MRPT_LOG(::mrpt::system::LVL_DEBUG, _STRING)
429 #define MRPT_LOG_INFO(_STRING) \
430  INTERNAL_MRPT_LOG(::mrpt::system::LVL_INFO, _STRING)
431 #define MRPT_LOG_WARN(_STRING) \
432  INTERNAL_MRPT_LOG(::mrpt::system::LVL_WARN, _STRING)
433 #define MRPT_LOG_ERROR(_STRING) \
434  INTERNAL_MRPT_LOG(::mrpt::system::LVL_ERROR, _STRING)
435 
436 /** Use: `MRPT_LOG_ONCE_DEBUG("once-only message");` */
437 #define MRPT_LOG_ONCE_DEBUG(_STRING) \
438  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_DEBUG, _STRING)
439 #define MRPT_LOG_ONCE_INFO(_STRING) \
440  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_INFO, _STRING)
441 #define MRPT_LOG_ONCE_WARN(_STRING) \
442  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_WARN, _STRING)
443 #define MRPT_LOG_ONCE_ERROR(_STRING) \
444  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_ERROR, _STRING)
445 
446 /** Use: `MRPT_LOG_THROTTLE_DEBUG(5.0, "message");` */
447 #define MRPT_LOG_THROTTLE_DEBUG(_PERIOD_SECONDS, _STRING) \
448  INTERNAL_MRPT_LOG_THROTTLE( \
449  ::mrpt::system::LVL_DEBUG, _PERIOD_SECONDS, _STRING)
450 #define MRPT_LOG_THROTTLE_INFO(_PERIOD_SECONDS, _STRING) \
451  INTERNAL_MRPT_LOG_THROTTLE( \
452  ::mrpt::system::LVL_INFO, _PERIOD_SECONDS, _STRING)
453 #define MRPT_LOG_THROTTLE_WARN(_PERIOD_SECONDS, _STRING) \
454  INTERNAL_MRPT_LOG_THROTTLE( \
455  ::mrpt::system::LVL_WARN, _PERIOD_SECONDS, _STRING)
456 #define MRPT_LOG_THROTTLE_ERROR(_PERIOD_SECONDS, _STRING) \
457  INTERNAL_MRPT_LOG_THROTTLE( \
458  ::mrpt::system::LVL_ERROR, _PERIOD_SECONDS, _STRING)
459 
460 /** Use: `MRPT_LOG_DEBUG_FMT("i=%u", i);` */
461 #define MRPT_LOG_DEBUG_FMT(_FMT_STRING, ...) \
462  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_DEBUG, _FMT_STRING, __VA_ARGS__)
463 #define MRPT_LOG_INFO_FMT(_FMT_STRING, ...) \
464  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_INFO, _FMT_STRING, __VA_ARGS__)
465 #define MRPT_LOG_WARN_FMT(_FMT_STRING, ...) \
466  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_WARN, _FMT_STRING, __VA_ARGS__)
467 #define MRPT_LOG_ERROR_FMT(_FMT_STRING, ...) \
468  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_ERROR, _FMT_STRING, __VA_ARGS__)
469 
470 /** Use: `MRPT_LOG_DEBUG_STREAM("Var=" << value << " foo=" << foo_var);` */
471 #define MRPT_LOG_DEBUG_STREAM(__CONTENTS) \
472  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_DEBUG, __CONTENTS)
473 #define MRPT_LOG_INFO_STREAM(__CONTENTS) \
474  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_INFO, __CONTENTS)
475 #define MRPT_LOG_WARN_STREAM(__CONTENTS) \
476  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_WARN, __CONTENTS)
477 #define MRPT_LOG_ERROR_STREAM(__CONTENTS) \
478  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_ERROR, __CONTENTS)
479 
480 /** Usage: `MRPT_LOG_THROTTLE_DEBUG_STREAM(5.0, "Var=" << value << " foo=" <<
481  * foo_var);` */
482 #define MRPT_LOG_THROTTLE_DEBUG_STREAM(_PERIOD_SECONDS, __CONTENTS) \
483  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
484  ::mrpt::system::LVL_DEBUG, _PERIOD_SECONDS, __CONTENTS)
485 #define MRPT_LOG_THROTTLE_INFO_STREAM(_PERIOD_SECONDS, __CONTENTS) \
486  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
487  ::mrpt::system::LVL_INFO, _PERIOD_SECONDS, __CONTENTS)
488 #define MRPT_LOG_THROTTLE_WARN_STREAM(_PERIOD_SECONDS, __CONTENTS) \
489  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
490  ::mrpt::system::LVL_WARN, _PERIOD_SECONDS, __CONTENTS)
491 #define MRPT_LOG_THROTTLE_ERROR_STREAM(_PERIOD_SECONDS, __CONTENTS) \
492  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
493  ::mrpt::system::LVL_ERROR, _PERIOD_SECONDS, __CONTENTS)
494 
495 /** Usage: `MRPT_LOG_THROTTLE_DEBUG_FMT(5.0, "i=%u", i);` */
496 #define MRPT_LOG_THROTTLE_DEBUG_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
497  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
498  ::mrpt::system::LVL_DEBUG, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
499 #define MRPT_LOG_THROTTLE_INFO_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
500  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
501  ::mrpt::system::LVL_INFO, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
502 #define MRPT_LOG_THROTTLE_WARN_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
503  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
504  ::mrpt::system::LVL_WARN, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
505 #define MRPT_LOG_THROTTLE_ERROR_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
506  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
507  ::mrpt::system::LVL_ERROR, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
508 
509 #ifdef _DEBUG
510 #define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::system::LVL_DEBUG
511 #else
512 #define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::system::LVL_DEBUG
513 #endif
514 
515 /** For calling any `MRPT_LOG_*()` macro from outside of an object inherited
516  * from COutputLogger.
517  * Debug level is `DEBUG` if build with `_DEBUG` preprocessor flag, `INFO`
518  * otherwise.
519  * Use:
520  * \code
521  * MRPT_UNSCOPED_LOGGER_START;
522  * MRPT_LOG_WARN("blah");
523  * MRPT_LOG_ERROR_STREAM("error: " << strval);
524  * MRPT_UNSCOPED_LOGGER_END;
525  * \endcode
526  */
527 #define MRPT_UNSCOPED_LOGGER_START \
528  do \
529  { \
530  struct dummy_logger_ : public mrpt::system::COutputLogger \
531  { \
532  dummy_logger_() : mrpt::system::COutputLogger("MRPT_log") \
533  { \
534  this->setMinLoggingLevel(DEFAULT_LOGLVL_MRPT_UNSCOPED); \
535  } \
536  void usercode() \
537  { \
538  do \
539  { \
540  } while (0)
541 // Here comes the user code, which is run in the ctor, and will call the object
542 // log methods.
543 
544 #define MRPT_UNSCOPED_LOGGER_END \
545  } \
546  } \
547  ; \
548  static dummy_logger_ tmp_obj; \
549  tmp_obj.usercode(); \
550  } \
551  while (0)
552 } // namespace system
553 } // namespace mrpt
554 // TTypeEnum for verbosity levels:
mrpt::system::COutputLogger::TMsg::TMsg
TMsg(const mrpt::system::VerbosityLevel level, const std::string &msg, const COutputLogger &logger)
Class constructor that passes a message in std::string form as well as a reference to the COutputLogg...
Definition: COutputLogger.cpp:211
os.h
mrpt::system::COutputLogger::TMsg::timestamp
mrpt::system::TTimeStamp timestamp
Timestamp of the message.
Definition: system/COutputLogger.h:299
mrpt::system::COutputLogger::logging_levels_to_colors
static mrpt::system::TConsoleColor logging_levels_to_colors[NUMBER_OF_VERBOSITY_LEVELS]
Map from VerbosityLevels to their corresponding mrpt::system::TConsoleColor.
Definition: system/COutputLogger.h:124
mrpt::system::COutputLogger::isLoggingLevelVisible
bool isLoggingLevelVisible(VerbosityLevel level) const
Definition: system/COutputLogger.h:201
mrpt::system::COutputLogger::logStr
void logStr(const VerbosityLevel level, const std::string &msg_str) const
Main method to add the specified message string to the logger.
Definition: COutputLogger.cpp:61
mrpt::system::COutputLoggerStreamWrapper::m_logger
const COutputLogger & m_logger
Definition: system/COutputLogger.h:347
mrpt::system::COutputLogger::TMsg::dumpToConsole
void dumpToConsole() const
Dump the message contents to the standard output.
Definition: COutputLogger.cpp:253
mrpt::system::COutputLogger::TMsg::reset
void reset()
Reset the contents of the TMsg instance.
Definition: COutputLogger.cpp:223
MRPT_ENUM_TYPE_END
#define MRPT_ENUM_TYPE_END()
Definition: TEnumType.h:74
mrpt::system::COutputLogger::TMsg::writeToStream
void writeToStream(std::ostream &out) const
Write the message contents to the specified stream.
Definition: COutputLogger.cpp:245
MRPT_FILL_ENUM_CUSTOM_NAME
MRPT_FILL_ENUM_CUSTOM_NAME(LVL_DEBUG, "DEBUG")
mrpt::system::COutputLogger::~COutputLogger
virtual ~COutputLogger()
virtual dtor (so we can derive classes from this one)
Definition: COutputLogger.cpp:60
mrpt::system::COutputLogger::setVerbosityLevel
void setVerbosityLevel(const VerbosityLevel level)
alias of setMinLoggingLevel()
Definition: COutputLogger.cpp:138
mrpt::system::COutputLogger::logging_enable_console_output
bool logging_enable_console_output
[Default=true] Set it to false in case you don't want the logged messages to be dumped to the output ...
Definition: system/COutputLogger.h:239
mrpt::system::COutputLoggerStreamWrapper::operator<<
std::stringstream & operator<<(const T &val)
Definition: system/COutputLogger.h:332
mrpt::system::COutputLogger::generateStringFromFormat
std::string generateStringFromFormat(const char *fmt, va_list argp) const
Helper method for generating a std::string instance from printf-like arguments.
Definition: COutputLogger.cpp:99
mrpt::system::COutputLogger::m_min_verbosity_level
VerbosityLevel m_min_verbosity_level
Provided messages with VerbosityLevel smaller than this value shall be ignored.
Definition: system/COutputLogger.h:252
mrpt::system::COutputLogger::writeLogToFile
void writeLogToFile(const std::string *fname_in=NULL) const
Write the contents of the COutputLogger instance to an external file.
Definition: COutputLogger.cpp:154
mrpt::system::COutputLogger::logging_enable_keep_record
bool logging_enable_keep_record
[Default=false] Enables storing all messages into an internal list.
Definition: system/COutputLogger.h:242
mrpt::system::COutputLogger::getLoggerLastMsg
std::string getLoggerLastMsg() const
Return the last Tmsg instance registered in the logger history.
Definition: COutputLogger.cpp:184
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::LVL_INFO
@ LVL_INFO
Definition: system/COutputLogger.h:31
level
GLint level
Definition: glext.h:3600
name
GLuint const GLchar * name
Definition: glext.h:4054
mrpt::system::TTimeStamp
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:31
mrpt::system::COutputLogger::getLoggerName
std::string getLoggerName() const
Return the name of the COutputLogger instance.
Definition: COutputLogger.cpp:132
mrpt::system::COutputLogger::logCond
void void logCond(const VerbosityLevel level, bool cond, const std::string &msg_str) const
Log the given message only if the condition is satisfied.
Definition: COutputLogger.cpp:120
mrpt::system::COutputLogger::getLogAsString
std::string getLogAsString() const
Get the history of COutputLogger instance in a string representation.
Definition: COutputLogger.cpp:148
val
int val
Definition: mrpt_jpeglib.h:955
mrpt::system::COutputLogger::logFmt
void logFmt(const VerbosityLevel level, const char *fmt,...) const MRPT_printf_format_check(3
Alternative logging method, which mimics the printf behavior.
Definition: COutputLogger.cpp:80
mrpt::system::COutputLogger::m_listCallbacks
std::deque< output_logger_callback_t > m_listCallbacks
Definition: system/COutputLogger.h:314
mrpt::system::VerbosityLevel
VerbosityLevel
Enumeration of available verbosity levels.
Definition: system/COutputLogger.h:28
mrpt::system::COutputLoggerStreamWrapper::m_level
VerbosityLevel m_level
Definition: system/COutputLogger.h:346
mrpt::system::COutputLoggerStreamWrapper::operator<<
std::stringstream & operator<<(const std::stringstream &val)
Definition: system/COutputLogger.h:338
mrpt::system::COutputLogger::TMsg::body
std::string body
Actual content of the message.
Definition: system/COutputLogger.h:303
TEnumType.h
mrpt::system::COutputLoggerStreamWrapper
For use in MRPT_LOG_DEBUG_STREAM(), etc.
Definition: system/COutputLogger.h:318
mrpt::system::COutputLogger::TMsg::level
VerbosityLevel level
Verbosity level of the message.
Definition: system/COutputLogger.h:300
mrpt::system::COutputLogger::TMsg::getAsString
std::string getAsString() const
Return a string representation of the underlying message.
Definition: COutputLogger.cpp:231
mrpt::system::COutputLogger::setMinLoggingLevel
void setMinLoggingLevel(const VerbosityLevel level)
Set the minimum logging level for which the incoming logs are going to be taken into account.
Definition: COutputLogger.cpp:133
mrpt::system::LVL_WARN
@ LVL_WARN
Definition: system/COutputLogger.h:32
MRPT_ENUM_TYPE_BEGIN_NAMESPACE
#define MRPT_ENUM_TYPE_BEGIN_NAMESPACE(_NAMESPACE, _ENUM_TYPE_WITH_NS)
Definition: TEnumType.h:70
MRPT_printf_format_check
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
Definition: common.h:158
mrpt::system::COutputLogger::TMsg::~TMsg
~TMsg()
Default Destructor.
Definition: COutputLogger.cpp:222
mrpt::system::COutputLogger::loggerReset
void loggerReset()
Reset the contents of the logger instance.
Definition: COutputLogger.cpp:195
mrpt::system::COutputLogger::logDeregisterCallback
bool logDeregisterCallback(output_logger_callback_t userFunc)
Definition: COutputLogger.cpp:287
mrpt::system::COutputLogger
Versatile class for consistent logging and management of output messages.
Definition: system/COutputLogger.h:117
mrpt::system::COutputLoggerStreamWrapper::COutputLoggerStreamWrapper
COutputLoggerStreamWrapper(VerbosityLevel level, const COutputLogger &logger)
Definition: system/COutputLogger.h:320
mrpt::system::LVL_DEBUG
@ LVL_DEBUG
Definition: system/COutputLogger.h:30
mrpt::system::COutputLogger::dumpLogToConsole
void dumpLogToConsole() const
Dump the current contents of the COutputLogger instance in the terminal window.
Definition: COutputLogger.cpp:179
mrpt::system::TConsoleColor
TConsoleColor
For use in setConsoleColor.
Definition: os.h:175
CTicTac.h
mrpt::system::COutputLogger::m_logger_name
std::string m_logger_name
Definition: system/COutputLogger.h:310
mrpt::system::COutputLogger::TMsg
Struct responsible of holding information relevant to the message (in std::string form) issued by the...
Definition: system/COutputLogger.h:267
void
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
mrpt::system::COutputLogger::logRegisterCallback
void logRegisterCallback(output_logger_callback_t userFunc)
Definition: COutputLogger.cpp:274
mrpt::system::LVL_ERROR
@ LVL_ERROR
Definition: system/COutputLogger.h:33
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::system::COutputLogger::logging_levels_to_names
static std::string logging_levels_to_names[NUMBER_OF_VERBOSITY_LEVELS]
Map from VerbosityLevels to their corresponding names.
Definition: system/COutputLogger.h:129
mrpt::system::COutputLogger::getMinLoggingLevel
VerbosityLevel getMinLoggingLevel() const
Definition: system/COutputLogger.h:200
mrpt::system::COutputLogger::setLoggerName
void setLoggerName(const std::string &name)
Set the name of the COutputLogger instance.
Definition: COutputLogger.cpp:127
mrpt::system::COutputLoggerStreamWrapper::~COutputLoggerStreamWrapper
~COutputLoggerStreamWrapper()
Definition: system/COutputLogger.h:325
mrpt::system::COutputLogger::m_history
std::deque< TMsg > m_history
Definition: system/COutputLogger.h:312
mrpt::system::NUMBER_OF_VERBOSITY_LEVELS
@ NUMBER_OF_VERBOSITY_LEVELS
Definition: system/COutputLogger.h:35
mrpt::system::COutputLogger::COutputLogger
COutputLogger()
Default class constructor.
Definition: COutputLogger.cpp:59
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
datetime.h
mrpt::system::COutputLoggerStreamWrapper::m_str
std::stringstream m_str
Definition: system/COutputLogger.h:345
mrpt::system::output_logger_callback_t
std::function< void(const std::string &msg, const mrpt::system::VerbosityLevel level, const std::string &loggerName, const mrpt::system::TTimeStamp timestamp)> output_logger_callback_t
Callback types for use with mrpt::system::COuputLogger.
Definition: system/COutputLogger.h:41
mrpt::system::COutputLogger::TMsg::name
std::string name
Name of the COutputLogger instance that called registered the message.
Definition: system/COutputLogger.h:301
MRPT_FILL_ENUM
MRPT_FILL_ENUM(LVL_DEBUG)



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST