MRPT  2.0.4
system/COutputLogger.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/core/Clock.h>
13 #include <mrpt/system/CTicTac.h>
14 #include <mrpt/system/os.h> // for console color constants
16 
17 #include <array>
18 #include <deque>
19 #include <functional>
20 #include <iosfwd>
21 #include <sstream>
22 #include <string>
23 #include <string_view>
24 
25 namespace mrpt::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(
40  std::string_view msg, const mrpt::system::VerbosityLevel level,
41  std::string_view loggerName, const mrpt::Clock::time_point 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 */
123  static std::array<mrpt::system::TConsoleColor, NUMBER_OF_VERBOSITY_LEVELS>&
125 
126  /** Map from VerbosityLevels to their corresponding names. Handy for
127  * printing the current message VerbosityLevel along with the actual content
128  */
129  static std::array<std::string, NUMBER_OF_VERBOSITY_LEVELS>&
131 
132  /** @name Logging methods
133  * @{ */
134 
135  /**
136  * \brief Construct a COutputLogger instance with the given name as the
137  * instance name.
138  *
139  * Call to this constructor can be used instead of first initializing the
140  * object and then explicitly setting the name like in the following case:
141  * \code
142  * COutputLogger a_logger;
143  * a_logger.setLoggerName("logger_name");
144  * \endcode
145  */
146  COutputLogger(std::string_view name);
147  /** Default class constructor. Name of the logger is initialized to "logStr"
148  */
149  COutputLogger();
150  /** virtual dtor (so we can derive classes from this one) */
151  virtual ~COutputLogger();
152 
153  /** \brief Main method to add the specified message string to the logger.
154  * \sa logCond, logFmt */
155  void logStr(const VerbosityLevel level, std::string_view msg_str)
156  const; // renamed from log() to avoid conflict with math ::log()
157 
158  /** \brief Alternative logging method, which mimics the printf behavior.
159  *
160  * Handy for not having to first use mrpt::format to pass a std::string
161  * message to logStr
162  *
163  * \code
164  * // instead of:
165  * logStr(mrpt::format("Today is the %d of %s, %d", 15, "July", 2016));
166  *
167  * // one can use:
168  * logFmt("Today is the %d of %s, %d", 15, "July", 2016);
169  * \endcode
170  *
171  * \sa logStr, logCond
172  */
173  void logFmt(const VerbosityLevel level, const char* fmt, ...) const
174  MRPT_printf_format_check(3, 4); // arg 1=this
175 
176  /** \brief Log the given message only if the condition is satisfied.
177  *
178  * \sa log, logFmt
179  */
180  void logCond(
181  const VerbosityLevel level, bool cond,
182  const std::string& msg_str) const;
183 
184  /** Set the name of the COutputLogger instance. \sa getLoggerName */
185  void setLoggerName(const std::string& name);
186  /** Return the name of the COutputLogger instance. \sa setLoggerName */
187  std::string getLoggerName() const;
188 
189  /** \brief Set the *minimum* logging level for which the incoming logs are
190  * going to be taken into account.
191  *
192  * String messages with specified VerbosityLevel smaller than the min, will
193  * not be outputted to the screen and neither will a record of them be
194  * stored in by the COutputLogger instance
195  */
196  void setMinLoggingLevel(const VerbosityLevel level);
197  /** alias of setMinLoggingLevel() */
198  void setVerbosityLevel(const VerbosityLevel level);
199 
200  /** \sa setMinLoggingLevel */
203  {
204  return m_min_verbosity_level <= level;
205  }
206 
207  /** Fill the provided string with the contents of the logger's history in
208  * std::string representation */
209  void getLogAsString(std::string& log_contents) const;
210  /** Get the history of COutputLogger instance in a string representation. */
211  std::string getLogAsString() const;
212 
213  /** \brief Write the contents of the COutputLogger instance to an external
214  * file.
215  *
216  * Upon call to this method, COutputLogger dumps the contents of all the
217  * logged commands so far to the specified external file. By default the
218  * filename is set to ${LOGGERNAME}.log except if the fname parameter is
219  * provided
220  *
221  * \sa dumpToConsole, getAsString
222  */
223  void writeLogToFile(const std::string* fname_in = nullptr) const;
224  /** \brief Dump the current contents of the COutputLogger instance in the
225  * terminal window.
226  *
227  * \sa writeToFile
228  */
229  void dumpLogToConsole() const;
230  /** Return the last Tmsg instance registered in the logger history */
231  std::string getLoggerLastMsg() const;
232  /** Fill inputtted string with the contents of the last message in history
233  */
234  void getLoggerLastMsg(std::string& msg_str) const;
235  /** Reset the contents of the logger instance. Called upon construction. */
236  void loggerReset();
237 
238  /** [Default=true] Set it to false in case you don't want the logged
239  * messages to be dumped to the output automatically. */
241  /** [Default=false] Enables storing all messages into an internal list. \sa
242  * writeLogToFile, getLogAsString */
244 
246  /** \return true if an entry was found and deleted. */
248  /** @} */
249 
250  protected:
251  /** \brief Provided messages with VerbosityLevel smaller than this value
252  * shall be ignored */
254 
255  private:
256  /**
257  * \brief Struct responsible of holding information relevant to the message
258  * (in std::string form) issued by the user.
259  *
260  * Upon TMsg initialization, instance fetches the name of the caller
261  * COutputLogger, as well as the VerbosityLevel and the
262  * mrpt::Clock::time_point of the message provided.
263  * The format of the message when this is printed / or written to an
264  * external file complies is given below:
265  *
266  * <center><em> [name | level | timestamp:] body </em></center>
267  */
268  struct TMsg
269  {
270  /** \brief Class constructor that passes a message in std::string
271  * form as well as a reference to the COutputLogger that provided the
272  * current message
273  */
274  TMsg(
275  const mrpt::system::VerbosityLevel level, std::string_view msg,
276  const COutputLogger& logger);
277  /** \brief Default Destructor */
278  ~TMsg();
279 
280  /** \brief Return a string representation of the underlying message */
281  std::string getAsString() const;
282  /** \brief Fill the string with the contents of the underlying message
283  * in
284  * string representation */
285  void getAsString(std::string* contents) const;
286  /** \brief Write the message contents to the specified stream
287  *
288  * \sa getAsString
289  */
290  void writeToStream(std::ostream& out) const;
291  /** \brief Dump the message contents to the standard output
292  *
293  * \sa writeToStream
294  */
295  void dumpToConsole() const;
296 
297  // parameters of the message under construction
298  mrpt::Clock::time_point timestamp; /**< Timestamp of the message. */
299  VerbosityLevel level; /**< Verbosity level of the message. */
300  std::string name; /**< Name of the COutputLogger instance that called
301  registered the message. */
302  std::string body; /**< Actual content of the message. */
303  };
304 
305  /** Helper method for generating a std::string instance from printf-like
306  * arguments */
307  std::string generateStringFromFormat(
308  std::string_view fmt, va_list argp) const;
309 
310  std::string m_logger_name;
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 bool 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 mrpt::system
553 // TTypeEnum for verbosity levels:
bool isLoggingLevelVisible(VerbosityLevel level) const
std::string generateStringFromFormat(std::string_view fmt, va_list argp) const
Helper method for generating a std::string instance from printf-like arguments.
#define MRPT_ENUM_TYPE_BEGIN_NAMESPACE(_NAMESPACE, _ENUM_TYPE_WITH_NS)
Definition: TEnumType.h:74
VerbosityLevel
Enumeration of available verbosity levels.
virtual ~COutputLogger()
virtual dtor (so we can derive classes from this one)
std::chrono::time_point< Clock > time_point
Definition: Clock.h:25
void logFmt(const VerbosityLevel level, const char *fmt,...) const MRPT_printf_format_check(3
Alternative logging method, which mimics the printf behavior.
void dumpToConsole() const
Dump the message contents to the standard output.
std::string getLoggerLastMsg() const
Return the last Tmsg instance registered in the logger history.
static std::array< std::string, NUMBER_OF_VERBOSITY_LEVELS > & logging_levels_to_names()
Map from VerbosityLevels to their corresponding names.
void setMinLoggingLevel(const VerbosityLevel level)
Set the minimum logging level for which the incoming logs are going to be taken into account...
MRPT_FILL_ENUM(LVL_DEBUG)
For use in MRPT_LOG_DEBUG_STREAM(), etc.
void writeToStream(std::ostream &out) const
Write the message contents to the specified stream.
std::deque< output_logger_callback_t > m_listCallbacks
bool logging_enable_keep_record
[Default=false] Enables storing all messages into an internal list.
VerbosityLevel level
Verbosity level of the message.
std::stringstream & operator<<(const T &val)
COutputLoggerStreamWrapper(VerbosityLevel level, const COutputLogger &logger)
VerbosityLevel getMinLoggingLevel() const
std::function< void(std::string_view msg, const mrpt::system::VerbosityLevel level, std::string_view loggerName, const mrpt::Clock::time_point timestamp)> output_logger_callback_t
Callback types for use with mrpt::system::COuputLogger.
static std::array< mrpt::system::TConsoleColor, NUMBER_OF_VERBOSITY_LEVELS > & logging_levels_to_colors()
Map from VerbosityLevels to their corresponding mrpt::system::TConsoleColor.
std::string getAsString() const
Return a string representation of the underlying message.
std::string body
Actual content of the message.
Versatile class for consistent logging and management of output messages.
std::string getLoggerName() const
Return the name of the COutputLogger instance.
void setLoggerName(const std::string &name)
Set the name of the COutputLogger instance.
void loggerReset()
Reset the contents of the logger instance.
int val
Definition: mrpt_jpeglib.h:957
void void logCond(const VerbosityLevel level, bool cond, const std::string &msg_str) const
Log the given message only if the condition is satisfied.
#define MRPT_ENUM_TYPE_END()
Definition: TEnumType.h:78
void dumpLogToConsole() const
Dump the current contents of the COutputLogger instance in the terminal window.
std::stringstream & operator<<(const std::stringstream &val)
mrpt::Clock::time_point timestamp
Timestamp of the message.
TMsg(const mrpt::system::VerbosityLevel level, std::string_view msg, const COutputLogger &logger)
Class constructor that passes a message in std::string form as well as a reference to the COutputLogg...
std::string getLogAsString() const
Get the history of COutputLogger instance in a string representation.
void setVerbosityLevel(const VerbosityLevel level)
alias of setMinLoggingLevel()
void logStr(const VerbosityLevel level, std::string_view msg_str) const
Main method to add the specified message string to the logger.
mrpt::vision::TStereoCalibResults out
COutputLogger()
Default class constructor.
Struct responsible of holding information relevant to the message (in std::string form) issued by the...
void logRegisterCallback(output_logger_callback_t userFunc)
std::string name
Name of the COutputLogger instance that called registered the message.
MRPT_FILL_ENUM_CUSTOM_NAME(LVL_DEBUG, "DEBUG")
VerbosityLevel m_min_verbosity_level
Provided messages with VerbosityLevel smaller than this value shall be ignored.
~TMsg()
Default Destructor.
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
Definition: common.h:142
bool logging_enable_console_output
[Default=true] Set it to false in case you don&#39;t want the logged messages to be dumped to the output ...
bool logDeregisterCallback(output_logger_callback_t userFunc)
void writeLogToFile(const std::string *fname_in=nullptr) const
Write the contents of the COutputLogger instance to an external file.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020