10 #ifndef COUTPUTLOGGER_H 11 #define COUTPUTLOGGER_H 38 NUMBER_OF_VERBOSITY_LEVELS
42 typedef void (*output_logger_callback_t)(
125 [NUMBER_OF_VERBOSITY_LEVELS];
133 static std::string logging_levels_to_names[NUMBER_OF_VERBOSITY_LEVELS];
154 virtual ~COutputLogger();
176 void logFmt(
const VerbosityLevel
level,
const char* fmt, ...) const
184 const VerbosityLevel
level,
bool cond,
185 const
std::
string& msg_str) const;
188 void setLoggerName(const
std::
string&
name);
190 std::
string getLoggerName() const;
199 void setMinLoggingLevel(const VerbosityLevel
level);
201 void setVerbosityLevel(const VerbosityLevel
level);
204 VerbosityLevel getMinLoggingLevel()
const {
return m_min_verbosity_level; }
205 bool isLoggingLevelVisible(VerbosityLevel
level)
const 207 return m_min_verbosity_level <=
level;
212 void getLogAsString(
std::string& log_contents)
const;
226 void writeLogToFile(
const std::string* fname_in = NULL)
const;
232 void dumpLogToConsole()
const;
243 bool logging_enable_console_output;
246 bool logging_enable_keep_record;
248 void logRegisterCallback(
249 output_logger_callback_t userFunc,
void* userParam = NULL);
250 void logDeregisterCallback(
251 output_logger_callback_t userFunc,
void* userParam = NULL);
254 struct TCallbackEntry
256 output_logger_callback_t func;
260 const mrpt::utils::COutputLogger::TCallbackEntry& e2)
const 262 return func < e2.func;
265 const mrpt::utils::COutputLogger::TCallbackEntry& c2)
const 267 return func == c2.func && userParam == c2.userParam;
274 VerbosityLevel m_min_verbosity_level;
297 const COutputLogger& logger);
316 void dumpToConsole()
const;
322 VerbosityLevel
level;
330 std::string generateStringFromFormat(
const char* fmt, va_list argp)
const;
333 mutable std::deque<TMsg>
336 std::set<TCallbackEntry> m_listCallbacks;
340 struct COutputLoggerStreamWrapper
342 COutputLoggerStreamWrapper(
343 VerbosityLevel
level,
const COutputLogger& logger)
344 : m_level(
level), m_logger(logger)
347 ~COutputLoggerStreamWrapper()
349 if (m_logger.isLoggingLevelVisible(m_level))
350 m_logger.logStr(m_level, m_str.str());
353 template <
typename T>
367 std::stringstream m_str;
368 VerbosityLevel m_level;
369 const COutputLogger& m_logger;
372 #define INTERNAL_MRPT_LOG(_LVL, _STRING) this->logStr(_LVL, _STRING) 374 #define INTERNAL_MRPT_LOG_ONCE(_LVL, _STRING) \ 377 static once_flag = false; \ 381 this->logStr(_LVL, _STRING); \ 385 #define INTERNAL_MRPT_LOG_FMT(_LVL, _FMT_STRING, ...) \ 388 if (this->isLoggingLevelVisible(_LVL)) \ 390 this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \ 394 #define INTERNAL_MRPT_LOG_STREAM(_LVL, __CONTENTS) \ 397 if (this->isLoggingLevelVisible(_LVL)) \ 399 ::mrpt::utils::COutputLoggerStreamWrapper(_LVL, *this) \ 404 #define INTERNAL_MRPT_LOG_THROTTLE(_LVL, _PERIOD_SECONDS, _STRING) \ 407 if (this->isLoggingLevelVisible(_LVL)) \ 409 static mrpt::utils::CTicTac tim; \ 410 if (tim.Tac() > _PERIOD_SECONDS) \ 413 this->logStr(_LVL, _STRING); \ 418 #define INTERNAL_MRPT_LOG_THROTTLE_STREAM(_LVL, _PERIOD_SECONDS, __CONTENTS) \ 421 if (this->isLoggingLevelVisible(_LVL)) \ 423 static mrpt::utils::CTicTac tim; \ 424 if (tim.Tac() > _PERIOD_SECONDS) \ 427 ::mrpt::utils::COutputLoggerStreamWrapper(_LVL, *this) \ 433 #define INTERNAL_MRPT_LOG_THROTTLE_FMT( \ 434 _LVL, _PERIOD_SECONDS, _FMT_STRING, ...) \ 437 if (this->isLoggingLevelVisible(_LVL)) \ 439 static mrpt::utils::CTicTac tim; \ 440 if (tim.Tac() > _PERIOD_SECONDS) \ 443 this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \ 449 #define MRPT_LOG_DEBUG(_STRING) \ 450 INTERNAL_MRPT_LOG(::mrpt::utils::LVL_DEBUG, _STRING) 451 #define MRPT_LOG_INFO(_STRING) \ 452 INTERNAL_MRPT_LOG(::mrpt::utils::LVL_INFO, _STRING) 453 #define MRPT_LOG_WARN(_STRING) \ 454 INTERNAL_MRPT_LOG(::mrpt::utils::LVL_WARN, _STRING) 455 #define MRPT_LOG_ERROR(_STRING) \ 456 INTERNAL_MRPT_LOG(::mrpt::utils::LVL_ERROR, _STRING) 459 #define MRPT_LOG_ONCE_DEBUG(_STRING) \ 460 INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_DEBUG, _STRING) 461 #define MRPT_LOG_ONCE_INFO(_STRING) \ 462 INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_INFO, _STRING) 463 #define MRPT_LOG_ONCE_WARN(_STRING) \ 464 INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_WARN, _STRING) 465 #define MRPT_LOG_ONCE_ERROR(_STRING) \ 466 INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_ERROR, _STRING) 469 #define MRPT_LOG_THROTTLE_DEBUG(_PERIOD_SECONDS, _STRING) \ 470 INTERNAL_MRPT_LOG_THROTTLE( \ 471 ::mrpt::utils::LVL_DEBUG, _PERIOD_SECONDS, _STRING) 472 #define MRPT_LOG_THROTTLE_INFO(_PERIOD_SECONDS, _STRING) \ 473 INTERNAL_MRPT_LOG_THROTTLE( \ 474 ::mrpt::utils::LVL_INFO, _PERIOD_SECONDS, _STRING) 475 #define MRPT_LOG_THROTTLE_WARN(_PERIOD_SECONDS, _STRING) \ 476 INTERNAL_MRPT_LOG_THROTTLE( \ 477 ::mrpt::utils::LVL_WARN, _PERIOD_SECONDS, _STRING) 478 #define MRPT_LOG_THROTTLE_ERROR(_PERIOD_SECONDS, _STRING) \ 479 INTERNAL_MRPT_LOG_THROTTLE( \ 480 ::mrpt::utils::LVL_ERROR, _PERIOD_SECONDS, _STRING) 483 #define MRPT_LOG_DEBUG_FMT(_FMT_STRING, ...) \ 484 INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_DEBUG, _FMT_STRING, __VA_ARGS__) 485 #define MRPT_LOG_INFO_FMT(_FMT_STRING, ...) \ 486 INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_INFO, _FMT_STRING, __VA_ARGS__) 487 #define MRPT_LOG_WARN_FMT(_FMT_STRING, ...) \ 488 INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_WARN, _FMT_STRING, __VA_ARGS__) 489 #define MRPT_LOG_ERROR_FMT(_FMT_STRING, ...) \ 490 INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_ERROR, _FMT_STRING, __VA_ARGS__) 493 #define MRPT_LOG_DEBUG_STREAM(__CONTENTS) \ 494 INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_DEBUG, __CONTENTS) 495 #define MRPT_LOG_INFO_STREAM(__CONTENTS) \ 496 INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_INFO, __CONTENTS) 497 #define MRPT_LOG_WARN_STREAM(__CONTENTS) \ 498 INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_WARN, __CONTENTS) 499 #define MRPT_LOG_ERROR_STREAM(__CONTENTS) \ 500 INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_ERROR, __CONTENTS) 504 #define MRPT_LOG_THROTTLE_DEBUG_STREAM(_PERIOD_SECONDS, __CONTENTS) \ 505 INTERNAL_MRPT_LOG_THROTTLE_STREAM( \ 506 ::mrpt::utils::LVL_DEBUG, _PERIOD_SECONDS, __CONTENTS) 507 #define MRPT_LOG_THROTTLE_INFO_STREAM(_PERIOD_SECONDS, __CONTENTS) \ 508 INTERNAL_MRPT_LOG_THROTTLE_STREAM( \ 509 ::mrpt::utils::LVL_INFO, _PERIOD_SECONDS, __CONTENTS) 510 #define MRPT_LOG_THROTTLE_WARN_STREAM(_PERIOD_SECONDS, __CONTENTS) \ 511 INTERNAL_MRPT_LOG_THROTTLE_STREAM( \ 512 ::mrpt::utils::LVL_WARN, _PERIOD_SECONDS, __CONTENTS) 513 #define MRPT_LOG_THROTTLE_ERROR_STREAM(_PERIOD_SECONDS, __CONTENTS) \ 514 INTERNAL_MRPT_LOG_THROTTLE_STREAM( \ 515 ::mrpt::utils::LVL_ERROR, _PERIOD_SECONDS, __CONTENTS) 518 #define MRPT_LOG_THROTTLE_DEBUG_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \ 519 INTERNAL_MRPT_LOG_THROTTLE_FMT( \ 520 ::mrpt::utils::LVL_DEBUG, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 521 #define MRPT_LOG_THROTTLE_INFO_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \ 522 INTERNAL_MRPT_LOG_THROTTLE_FMT( \ 523 ::mrpt::utils::LVL_INFO, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 524 #define MRPT_LOG_THROTTLE_WARN_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \ 525 INTERNAL_MRPT_LOG_THROTTLE_FMT( \ 526 ::mrpt::utils::LVL_WARN, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 527 #define MRPT_LOG_THROTTLE_ERROR_FMT(_PERIOD_SECONDS, _FMT_STRING, ...) \ 528 INTERNAL_MRPT_LOG_THROTTLE_FMT( \ 529 ::mrpt::utils::LVL_ERROR, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 532 #define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::utils::LVL_DEBUG 534 #define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::utils::LVL_DEBUG 548 #define MRPT_UNSCOPED_LOGGER_START \ 551 struct dummy_logger_ : public mrpt::utils::COutputLogger \ 553 dummy_logger_() : mrpt::utils::COutputLogger("MRPT_log") \ 555 this->setMinLoggingLevel(DEFAULT_LOGLVL_MRPT_UNSCOPED); \ 562 // Here comes the user code, which is run in the ctor, and will call the object 565 #define MRPT_UNSCOPED_LOGGER_END \ 569 static dummy_logger_ tmp_obj; \ 570 tmp_obj.usercode(); \ 578 struct TEnumTypeFiller<
mrpt::utils::VerbosityLevel>
580 typedef mrpt::utils::VerbosityLevel
enum_t;
581 static void fill(bimap<enum_t, std::string>& m_map)
584 m_map.insert(LVL_DEBUG,
"DEBUG");
585 m_map.insert(LVL_DEBUG,
"LVL_DEBUG");
586 m_map.insert(LVL_INFO,
"INFO");
587 m_map.insert(LVL_INFO,
"LVL_INFO");
588 m_map.insert(LVL_WARN,
"WARN");
589 m_map.insert(LVL_WARN,
"LVL_WARN");
590 m_map.insert(LVL_ERROR,
"ERROR");
591 m_map.insert(LVL_ERROR,
"LVL_ERROR");
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
static void fill(mrpt::utils::bimap< enum_t, std::string > &m_map)
bool operator==(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
TConsoleColor
For use in setConsoleColor.
CStream & operator<<(mrpt::utils::CStream &s, const char *a)
GLsizei const GLchar ** string
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLuint const GLchar * name
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
bool operator<(const TMatchingPair &a, const TMatchingPair &b)
A comparison operator, for sorting lists of TMatchingPair's, first order by this_idx, if equals, by other_idx.