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/core/Clock.h>
16 
17 #include <string>
18 #include <deque>
19 #include <array>
20 #include <sstream>
21 #include <iosfwd>
22 #include <functional>
23 
24 namespace mrpt::system
25 {
26 /** \brief Enumeration of available verbosity levels. \sa COutputLogger */
28 {
29  LVL_DEBUG = 0,
33  // ------------
35 };
36 
37 /** Callback types for use with mrpt::system::COuputLogger */
38 using output_logger_callback_t = std::function<void(
40  const std::string& loggerName, const mrpt::Clock::time_point &timestamp)>;
41 
42 /** \brief Versatile class for consistent logging and
43  * management of output messages
44  *
45  * COutputLogger is a versatile class for logging messages either to the
46  * terminal window or to an external file. Class instances can take messages in
47  * std::string using the logStr class methods. The following macros are also
48  * provided
49  * for usage within a class that inherits from COutputLogger:
50  *
51  * \code
52  * // Plain strings:
53  * MRPT_LOG_DEBUG("This will be shown only if verbosity level is LVL_DEBUG.");
54  * MRPT_LOG_ERROR("This message will be always shown.");
55  * // printf-like versions:
56  * MRPT_LOG_ERROR_FMT("Out of range value: %i.", int_param);
57  * // stream-like versions:
58  * MRPT_LOG_ERROR_STREAM("Out of range value: " << int_param << " more vars: "
59  * << other_var);
60  * // Minimum period (in seconds) between messages:
61  * MRPT_LOG_THROTTLE_DEBUG_STREAM(5.0, "Var=" << value << " foo=" << foo_var);
62  * // Only once:
63  * MRPT_LOG_ONCE_WARN("Notice: blah blah");
64  * \endcode
65  *
66  * From outside of a class inheriting from COutputLogger the following
67  * `MRPT_UNSCOPED_{START|END}` macros are provided:
68  *
69  * \code
70  * MRPT_UNSCOPED_LOGGER_START;
71  * MRPT_LOG_WARN("blah");
72  * MRPT_LOG_ERROR_STREAM("error: " << strval);
73  * MRPT_UNSCOPED_LOGGER_END;
74  * \endcode
75  *
76  * - Logger instance keeps the messages in an internal container so that upon
77  * request it can dump them either to the console or to an external file
78  * altogether.
79  * - The message, when printed in the terminal window, is **colored** according
80  * to
81  * the logger's current verbosity/logging level (Logging level with which
82  * the underlying TMsg instance was instantiatedd). The available verbosity
83  * levels as well as their corresponding colors are listed below:
84  *
85  * + LVL_DEBUG => CONCOL_BLUE
86  * + LVL_INFO => CONCOL_NORMAL
87  * + LVL_WARN => CONCOL_GREEN
88  * + LVL_ERROR => CONCOL_RED
89  *
90  * - Logged messages are displayed in the screen if the current logger level is
91  * higher than m_min_verbosity_level (logger ignores those messages
92  * altogether). This can be used for filtering the output messages according
93  * to their importance (e.g. show only error messages by issuing
94  * setMinLoggingLevel(LVL_ERROR)).
95  * \sa setLoggingLevel, setMinLoggingLevel
96  *
97  * Default logging level is LVL_INFO.
98  *
99  * User may receive callbacks whenever a message is displayed to console by
100  * using
101  * logRegisterCallback(). If for some reason the callbacks are not needed any
102  * more,
103  * use logDeregisterCallback() to stop receiving calls. This mechanism is useful
104  * in case of showing the messages to a GUI, transmiting them to a remote
105  * machine, etc.
106  *
107  * \note By default every logged message is going to be dumped to the standard
108  * output as well (if VerbosityLevel > m_min_verbosity_level). Unset \b
109  * logging_enable_console_output class variable if that's not the desired
110  * behavior
111  *
112  * \note [New in MRPT 1.5.0]
113  * \sa TMsg
114  * \ingroup mrpt_system_grp
115  */
117 {
118  public:
119  /** Map from VerbosityLevels to their corresponding
120  * mrpt::system::TConsoleColor. Handy for coloring the input based on the
121  * verbosity of the message */
122  static std::array<mrpt::system::TConsoleColor, NUMBER_OF_VERBOSITY_LEVELS>&
124 
125  /** Map from VerbosityLevels to their corresponding names. Handy for
126  * printing the current message VerbosityLevel along with the actual content
127  */
128  static std::array<std::string, NUMBER_OF_VERBOSITY_LEVELS>&
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::Clock::time_point 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 
296  // parameters of the message under construction
297  mrpt::Clock::time_point timestamp; /**< Timestamp of the message. */
298  VerbosityLevel level; /**< Verbosity level of the message. */
299  std::string name; /**< Name of the COutputLogger instance that called
300  registered the message. */
301  std::string body; /**< Actual content of the message. */
302  };
303 
304  /** Helper method for generating a std::string instance from printf-like
305  * arguments */
306  std::string generateStringFromFormat(const char* fmt, va_list argp) const;
307 
309  mutable std::deque<TMsg>
310  m_history; // deque is better than vector to avoid memory reallocs
311 
312  std::deque<output_logger_callback_t> m_listCallbacks;
313 };
314 
315 /** For use in MRPT_LOG_DEBUG_STREAM(), etc. */
317 {
319  VerbosityLevel level, const COutputLogger& logger)
320  : m_level(level), m_logger(logger)
321  {
322  }
324  {
326  m_logger.logStr(m_level, m_str.str());
327  }
328 
329  template <typename T>
330  std::stringstream& operator<<(const T& val)
331  {
332  m_str << val;
333  return m_str;
334  }
335  // Overload for std::stringstream objects
336  std::stringstream& operator<<(const std::stringstream& val)
337  {
338  m_str << val.str();
339  return m_str;
340  }
341 
342  private:
343  std::stringstream m_str;
346 };
347 
348 #define INTERNAL_MRPT_LOG(_LVL, _STRING) this->logStr(_LVL, _STRING)
349 
350 #define INTERNAL_MRPT_LOG_ONCE(_LVL, _STRING) \
351  do \
352  { \
353  static once_flag = false; \
354  if (!once_flag) \
355  { \
356  once_flag = true; \
357  this->logStr(_LVL, _STRING); \
358  } \
359  } while (0)
360 
361 #define INTERNAL_MRPT_LOG_FMT(_LVL, _FMT_STRING, ...) \
362  do \
363  { \
364  if (this->isLoggingLevelVisible(_LVL)) \
365  { \
366  this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \
367  } \
368  } while (0)
369 
370 #define INTERNAL_MRPT_LOG_STREAM(_LVL, __CONTENTS) \
371  do \
372  { \
373  if (this->isLoggingLevelVisible(_LVL)) \
374  { \
375  ::mrpt::system::COutputLoggerStreamWrapper(_LVL, *this) \
376  << __CONTENTS; \
377  } \
378  } while (0)
379 
380 #define INTERNAL_MRPT_LOG_THROTTLE(_LVL, _PERIOD_SECONDS, _STRING) \
381  do \
382  { \
383  if (this->isLoggingLevelVisible(_LVL)) \
384  { \
385  static mrpt::system::CTicTac tim; \
386  if (tim.Tac() > _PERIOD_SECONDS) \
387  { \
388  tim.Tic(); \
389  this->logStr(_LVL, _STRING); \
390  } \
391  } \
392  } while (0)
393 
394 #define INTERNAL_MRPT_LOG_THROTTLE_STREAM(_LVL, _PERIOD_SECONDS, __CONTENTS) \
395  do \
396  { \
397  if (this->isLoggingLevelVisible(_LVL)) \
398  { \
399  static mrpt::system::CTicTac tim; \
400  if (tim.Tac() > _PERIOD_SECONDS) \
401  { \
402  tim.Tic(); \
403  ::mrpt::system::COutputLoggerStreamWrapper(_LVL, *this) \
404  << __CONTENTS; \
405  } \
406  } \
407  } while (0)
408 
409 #define INTERNAL_MRPT_LOG_THROTTLE_FMT( \
410  _LVL, _PERIOD_SECONDS, _FMT_STRING, ...) \
411  do \
412  { \
413  if (this->isLoggingLevelVisible(_LVL)) \
414  { \
415  static mrpt::system::CTicTac tim; \
416  if (tim.Tac() > _PERIOD_SECONDS) \
417  { \
418  tim.Tic(); \
419  this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \
420  } \
421  } \
422  } while (0)
423 
424 /** Use: `MRPT_LOG_DEBUG("message");` */
425 #define MRPT_LOG_DEBUG(_STRING) \
426  INTERNAL_MRPT_LOG(::mrpt::system::LVL_DEBUG, _STRING)
427 #define MRPT_LOG_INFO(_STRING) \
428  INTERNAL_MRPT_LOG(::mrpt::system::LVL_INFO, _STRING)
429 #define MRPT_LOG_WARN(_STRING) \
430  INTERNAL_MRPT_LOG(::mrpt::system::LVL_WARN, _STRING)
431 #define MRPT_LOG_ERROR(_STRING) \
432  INTERNAL_MRPT_LOG(::mrpt::system::LVL_ERROR, _STRING)
433 
434 /** Use: `MRPT_LOG_ONCE_DEBUG("once-only message");` */
435 #define MRPT_LOG_ONCE_DEBUG(_STRING) \
436  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_DEBUG, _STRING)
437 #define MRPT_LOG_ONCE_INFO(_STRING) \
438  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_INFO, _STRING)
439 #define MRPT_LOG_ONCE_WARN(_STRING) \
440  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_WARN, _STRING)
441 #define MRPT_LOG_ONCE_ERROR(_STRING) \
442  INTERNAL_MRPT_LOG_ONCE(::mrpt::system::LVL_ERROR, _STRING)
443 
444 /** Use: `MRPT_LOG_THROTTLE_DEBUG(5.0, "message");` */
445 #define MRPT_LOG_THROTTLE_DEBUG(_PERIOD_SECONDS, _STRING) \
446  INTERNAL_MRPT_LOG_THROTTLE( \
447  ::mrpt::system::LVL_DEBUG, _PERIOD_SECONDS, _STRING)
448 #define MRPT_LOG_THROTTLE_INFO(_PERIOD_SECONDS, _STRING) \
449  INTERNAL_MRPT_LOG_THROTTLE( \
450  ::mrpt::system::LVL_INFO, _PERIOD_SECONDS, _STRING)
451 #define MRPT_LOG_THROTTLE_WARN(_PERIOD_SECONDS, _STRING) \
452  INTERNAL_MRPT_LOG_THROTTLE( \
453  ::mrpt::system::LVL_WARN, _PERIOD_SECONDS, _STRING)
454 #define MRPT_LOG_THROTTLE_ERROR(_PERIOD_SECONDS, _STRING) \
455  INTERNAL_MRPT_LOG_THROTTLE( \
456  ::mrpt::system::LVL_ERROR, _PERIOD_SECONDS, _STRING)
457 
458 /** Use: `MRPT_LOG_DEBUG_FMT("i=%u", i);` */
459 #define MRPT_LOG_DEBUG_FMT(_FMT_STRING, ...) \
460  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_DEBUG, _FMT_STRING, __VA_ARGS__)
461 #define MRPT_LOG_INFO_FMT(_FMT_STRING, ...) \
462  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_INFO, _FMT_STRING, __VA_ARGS__)
463 #define MRPT_LOG_WARN_FMT(_FMT_STRING, ...) \
464  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_WARN, _FMT_STRING, __VA_ARGS__)
465 #define MRPT_LOG_ERROR_FMT(_FMT_STRING, ...) \
466  INTERNAL_MRPT_LOG_FMT(::mrpt::system::LVL_ERROR, _FMT_STRING, __VA_ARGS__)
467 
468 /** Use: `MRPT_LOG_DEBUG_STREAM("Var=" << value << " foo=" << foo_var);` */
469 #define MRPT_LOG_DEBUG_STREAM(__CONTENTS) \
470  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_DEBUG, __CONTENTS)
471 #define MRPT_LOG_INFO_STREAM(__CONTENTS) \
472  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_INFO, __CONTENTS)
473 #define MRPT_LOG_WARN_STREAM(__CONTENTS) \
474  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_WARN, __CONTENTS)
475 #define MRPT_LOG_ERROR_STREAM(__CONTENTS) \
476  INTERNAL_MRPT_LOG_STREAM(::mrpt::system::LVL_ERROR, __CONTENTS)
477 
478 /** Usage: `MRPT_LOG_THROTTLE_DEBUG_STREAM(5.0, "Var=" << value << " foo=" <<
479  * foo_var);` */
480 #define MRPT_LOG_THROTTLE_DEBUG_STREAM(_PERIOD_SECONDS, __CONTENTS) \
481  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
482  ::mrpt::system::LVL_DEBUG, _PERIOD_SECONDS, __CONTENTS)
483 #define MRPT_LOG_THROTTLE_INFO_STREAM(_PERIOD_SECONDS, __CONTENTS) \
484  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
485  ::mrpt::system::LVL_INFO, _PERIOD_SECONDS, __CONTENTS)
486 #define MRPT_LOG_THROTTLE_WARN_STREAM(_PERIOD_SECONDS, __CONTENTS) \
487  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
488  ::mrpt::system::LVL_WARN, _PERIOD_SECONDS, __CONTENTS)
489 #define MRPT_LOG_THROTTLE_ERROR_STREAM(_PERIOD_SECONDS, __CONTENTS) \
490  INTERNAL_MRPT_LOG_THROTTLE_STREAM( \
491  ::mrpt::system::LVL_ERROR, _PERIOD_SECONDS, __CONTENTS)
492 
493 /** Usage: `MRPT_LOG_THROTTLE_DEBUG_FMT(5.0, "i=%u", i);` */
494 #define MRPT_LOG_THROTTLE_DEBUG_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
495  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
496  ::mrpt::system::LVL_DEBUG, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
497 #define MRPT_LOG_THROTTLE_INFO_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
498  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
499  ::mrpt::system::LVL_INFO, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
500 #define MRPT_LOG_THROTTLE_WARN_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
501  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
502  ::mrpt::system::LVL_WARN, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
503 #define MRPT_LOG_THROTTLE_ERROR_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \
504  INTERNAL_MRPT_LOG_THROTTLE_FMT( \
505  ::mrpt::system::LVL_ERROR, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__)
506 
507 #ifdef _DEBUG
508 #define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::system::LVL_DEBUG
509 #else
510 #define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::system::LVL_DEBUG
511 #endif
512 
513 /** For calling any `MRPT_LOG_*()` macro from outside of an object inherited
514  * from COutputLogger.
515  * Debug level is `DEBUG` if build with `_DEBUG` preprocessor flag, `INFO`
516  * otherwise.
517  * Use:
518  * \code
519  * MRPT_UNSCOPED_LOGGER_START;
520  * MRPT_LOG_WARN("blah");
521  * MRPT_LOG_ERROR_STREAM("error: " << strval);
522  * MRPT_UNSCOPED_LOGGER_END;
523  * \endcode
524  */
525 #define MRPT_UNSCOPED_LOGGER_START \
526  do \
527  { \
528  struct dummy_logger_ : public mrpt::system::COutputLogger \
529  { \
530  dummy_logger_() : mrpt::system::COutputLogger("MRPT_log") \
531  { \
532  this->setMinLoggingLevel(DEFAULT_LOGLVL_MRPT_UNSCOPED); \
533  } \
534  void usercode() \
535  { \
536  do \
537  { \
538  } while (0)
539 // Here comes the user code, which is run in the ctor, and will call the object
540 // log methods.
541 
542 #define MRPT_UNSCOPED_LOGGER_END \
543  } \
544  } \
545  ; \
546  static dummy_logger_ tmp_obj; \
547  tmp_obj.usercode(); \
548  } \
549  while (0)
550 } // namespace mrpt::system
551 // TTypeEnum for verbosity levels:
bool isLoggingLevelVisible(VerbosityLevel level) const
#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:26
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...
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::string generateStringFromFormat(const char *fmt, va_list argp) const
Helper method for generating a std::string instance from printf-like arguments.
std::stringstream & operator<<(const T &val)
COutputLoggerStreamWrapper(VerbosityLevel level, const COutputLogger &logger)
VerbosityLevel getMinLoggingLevel() const
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:955
void writeLogToFile(const std::string *fname_in=NULL) const
Write the contents of the COutputLogger instance to an external file.
std::function< void(const std::string &msg, const mrpt::system::VerbosityLevel level, const std::string &loggerName, const mrpt::Clock::time_point &timestamp)> output_logger_callback_t
Callback types for use with mrpt::system::COuputLogger.
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)
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::Clock::time_point timestamp
Timestamp of the message.
std::string getLogAsString() const
Get the history of COutputLogger instance in a string representation.
void setVerbosityLevel(const VerbosityLevel level)
alias of setMinLoggingLevel()
COutputLogger()
Default class constructor.
Struct responsible of holding information relevant to the message (in std::string form) issued by the...
GLint level
Definition: glext.h:3600
GLuint const GLchar * name
Definition: glext.h:4054
void logRegisterCallback(output_logger_callback_t userFunc)
std::string name
Name of the COutputLogger instance that called registered the message.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
MRPT_FILL_ENUM_CUSTOM_NAME(LVL_DEBUG, "DEBUG")
void logStr(const VerbosityLevel level, const std::string &msg_str) const
Main method to add the specified message string to the logger.
VerbosityLevel m_min_verbosity_level
Provided messages with VerbosityLevel smaller than this value shall be ignored.
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
Definition: common.h:158
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)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020