10 #ifndef COUTPUTLOGGER_H 11 #define COUTPUTLOGGER_H 36 NUMBER_OF_VERBOSITY_LEVELS
112 static std::string logging_levels_to_names[NUMBER_OF_VERBOSITY_LEVELS];
130 virtual ~COutputLogger();
157 void logCond(const VerbosityLevel
level,
bool cond, const
std::
string& msg_str) const;
159 void setLoggerName(const
std::
string&
name);
160 std::
string getLoggerName() const;
168 void setMinLoggingLevel(const VerbosityLevel
level);
170 void setVerbosityLevel(const VerbosityLevel
level);
173 VerbosityLevel getMinLoggingLevel()
const {
return m_min_verbosity_level; }
174 bool isLoggingLevelVisible(VerbosityLevel
level)
const {
return m_min_verbosity_level <=
level; }
176 void getLogAsString(
std::string& log_contents)
const;
188 void writeLogToFile(
const std::string* fname_in = NULL)
const;
194 void dumpLogToConsole()
const;
199 bool logging_enable_console_output;
200 bool logging_enable_keep_record;
202 void logRegisterCallback(output_logger_callback_t userFunc,
void *userParam = NULL);
203 void logDeregisterCallback(output_logger_callback_t userFunc,
void *userParam = NULL);
208 output_logger_callback_t func;
211 bool operator <(
const mrpt::utils::COutputLogger::TCallbackEntry &e2)
const {
212 return func < e2.func;
214 bool operator == (
const mrpt::utils::COutputLogger::TCallbackEntry &c2)
const {
215 return func == c2.func && userParam == c2.userParam;
222 VerbosityLevel m_min_verbosity_level;
241 TMsg(
const mrpt::utils::VerbosityLevel
level,
const std::string& msg,
const COutputLogger& logger);
259 void dumpToConsole()
const;
265 VerbosityLevel
level;
270 std::string generateStringFromFormat(
const char* fmt, va_list argp)
const;
273 mutable std::deque<TMsg> m_history;
275 std::set<TCallbackEntry> m_listCallbacks;
281 COutputLoggerStreamWrapper(VerbosityLevel
level,
const COutputLogger &logger) : m_level(
level), m_logger(logger) {}
282 ~COutputLoggerStreamWrapper() {
if (m_logger.isLoggingLevelVisible(m_level)) m_logger.logStr(m_level, m_str.str()); }
284 template <
typename T>
296 std::stringstream m_str;
297 VerbosityLevel m_level;
298 const COutputLogger &m_logger;
301 #define INTERNAL_MRPT_LOG(_LVL,_STRING) \ 302 this->logStr(_LVL, _STRING) 304 #define INTERNAL_MRPT_LOG_ONCE(_LVL, _STRING) \ 306 static once_flag = false; \ 309 this->logStr(_LVL, _STRING); \ 312 #define INTERNAL_MRPT_LOG_FMT(_LVL,_FMT_STRING,...) \ 314 if (this->isLoggingLevelVisible(_LVL)) { \ 315 this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \ 318 #define INTERNAL_MRPT_LOG_STREAM(_LVL, __CONTENTS) \ 320 if (this->isLoggingLevelVisible(_LVL)) { \ 321 ::mrpt::utils::COutputLoggerStreamWrapper(_LVL, *this) << __CONTENTS; \ 324 #define INTERNAL_MRPT_LOG_THROTTLE(_LVL,_PERIOD_SECONDS, _STRING) \ 326 if (this->isLoggingLevelVisible(_LVL)) { \ 327 static mrpt::utils::CTicTac tim; \ 328 if (tim.Tac()>_PERIOD_SECONDS) { \ 330 this->logStr(_LVL, _STRING); \ 333 #define INTERNAL_MRPT_LOG_THROTTLE_STREAM(_LVL,_PERIOD_SECONDS, __CONTENTS) \ 335 if (this->isLoggingLevelVisible(_LVL)) { \ 336 static mrpt::utils::CTicTac tim; \ 337 if (tim.Tac()>_PERIOD_SECONDS) { \ 339 ::mrpt::utils::COutputLoggerStreamWrapper(_LVL, *this) << __CONTENTS; \ 342 #define INTERNAL_MRPT_LOG_THROTTLE_FMT(_LVL,_PERIOD_SECONDS,_FMT_STRING,...) \ 344 if (this->isLoggingLevelVisible(_LVL)) { \ 345 static mrpt::utils::CTicTac tim; \ 346 if (tim.Tac()>_PERIOD_SECONDS) { \ 348 this->logFmt(_LVL, _FMT_STRING, __VA_ARGS__); \ 353 #define MRPT_LOG_DEBUG(_STRING) INTERNAL_MRPT_LOG(::mrpt::utils::LVL_DEBUG, _STRING) 354 #define MRPT_LOG_INFO( _STRING) INTERNAL_MRPT_LOG(::mrpt::utils::LVL_INFO, _STRING) 355 #define MRPT_LOG_WARN( _STRING) INTERNAL_MRPT_LOG(::mrpt::utils::LVL_WARN, _STRING) 356 #define MRPT_LOG_ERROR(_STRING) INTERNAL_MRPT_LOG(::mrpt::utils::LVL_ERROR, _STRING) 359 #define MRPT_LOG_ONCE_DEBUG(_STRING) INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_DEBUG, _STRING) 360 #define MRPT_LOG_ONCE_INFO( _STRING) INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_INFO, _STRING) 361 #define MRPT_LOG_ONCE_WARN( _STRING) INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_WARN, _STRING) 362 #define MRPT_LOG_ONCE_ERROR(_STRING) INTERNAL_MRPT_LOG_ONCE(::mrpt::utils::LVL_ERROR, _STRING) 365 #define MRPT_LOG_THROTTLE_DEBUG(_PERIOD_SECONDS,_STRING) INTERNAL_MRPT_LOG_THROTTLE(::mrpt::utils::LVL_DEBUG,_PERIOD_SECONDS, _STRING) 366 #define MRPT_LOG_THROTTLE_INFO( _PERIOD_SECONDS,_STRING) INTERNAL_MRPT_LOG_THROTTLE(::mrpt::utils::LVL_INFO, _PERIOD_SECONDS, _STRING) 367 #define MRPT_LOG_THROTTLE_WARN( _PERIOD_SECONDS,_STRING) INTERNAL_MRPT_LOG_THROTTLE(::mrpt::utils::LVL_WARN, _PERIOD_SECONDS, _STRING) 368 #define MRPT_LOG_THROTTLE_ERROR(_PERIOD_SECONDS,_STRING) INTERNAL_MRPT_LOG_THROTTLE(::mrpt::utils::LVL_ERROR,_PERIOD_SECONDS, _STRING) 371 #define MRPT_LOG_DEBUG_FMT(_FMT_STRING,...) INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_DEBUG, _FMT_STRING, __VA_ARGS__) 372 #define MRPT_LOG_INFO_FMT( _FMT_STRING,...) INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_INFO, _FMT_STRING, __VA_ARGS__) 373 #define MRPT_LOG_WARN_FMT( _FMT_STRING,...) INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_WARN, _FMT_STRING, __VA_ARGS__) 374 #define MRPT_LOG_ERROR_FMT(_FMT_STRING,...) INTERNAL_MRPT_LOG_FMT(::mrpt::utils::LVL_ERROR, _FMT_STRING, __VA_ARGS__) 377 #define MRPT_LOG_DEBUG_STREAM(__CONTENTS) INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_DEBUG,__CONTENTS) 378 #define MRPT_LOG_INFO_STREAM( __CONTENTS) INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_INFO, __CONTENTS) 379 #define MRPT_LOG_WARN_STREAM( __CONTENTS) INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_WARN, __CONTENTS) 380 #define MRPT_LOG_ERROR_STREAM(__CONTENTS) INTERNAL_MRPT_LOG_STREAM(::mrpt::utils::LVL_ERROR,__CONTENTS) 383 #define MRPT_LOG_THROTTLE_DEBUG_STREAM(_PERIOD_SECONDS,__CONTENTS) INTERNAL_MRPT_LOG_THROTTLE_STREAM(::mrpt::utils::LVL_DEBUG,_PERIOD_SECONDS,__CONTENTS) 384 #define MRPT_LOG_THROTTLE_INFO_STREAM( _PERIOD_SECONDS,__CONTENTS) INTERNAL_MRPT_LOG_THROTTLE_STREAM(::mrpt::utils::LVL_INFO, _PERIOD_SECONDS,__CONTENTS) 385 #define MRPT_LOG_THROTTLE_WARN_STREAM( _PERIOD_SECONDS,__CONTENTS) INTERNAL_MRPT_LOG_THROTTLE_STREAM(::mrpt::utils::LVL_WARN, _PERIOD_SECONDS,__CONTENTS) 386 #define MRPT_LOG_THROTTLE_ERROR_STREAM(_PERIOD_SECONDS,__CONTENTS) INTERNAL_MRPT_LOG_THROTTLE_STREAM(::mrpt::utils::LVL_ERROR,_PERIOD_SECONDS,__CONTENTS) 389 #define MRPT_LOG_THROTTLE_DEBUG_FMT(_PERIOD_SECONDS,_FMT_STRING,...) INTERNAL_MRPT_LOG_THROTTLE_FMT(::mrpt::utils::LVL_DEBUG,_PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 390 #define MRPT_LOG_THROTTLE_INFO_FMT( _PERIOD_SECONDS,_FMT_STRING,...) INTERNAL_MRPT_LOG_THROTTLE_FMT(::mrpt::utils::LVL_INFO, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 391 #define MRPT_LOG_THROTTLE_WARN_FMT( _PERIOD_SECONDS,_FMT_STRING,...) INTERNAL_MRPT_LOG_THROTTLE_FMT(::mrpt::utils::LVL_WARN, _PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 392 #define MRPT_LOG_THROTTLE_ERROR_FMT(_PERIOD_SECONDS,_FMT_STRING,...) INTERNAL_MRPT_LOG_THROTTLE_FMT(::mrpt::utils::LVL_ERROR,_PERIOD_SECONDS, _FMT_STRING, __VA_ARGS__) 396 # define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::utils::LVL_DEBUG 398 # define DEFAULT_LOGLVL_MRPT_UNSCOPED ::mrpt::utils::LVL_DEBUG 410 #define MRPT_UNSCOPED_LOGGER_START \ 412 struct dummy_logger_ : public mrpt::utils::COutputLogger { \ 413 dummy_logger_() : mrpt::utils::COutputLogger("MRPT_log") { \ 414 this->setMinLoggingLevel(DEFAULT_LOGLVL_MRPT_UNSCOPED); \ 418 // Here comes the user code, which is run in the ctor, and will call the object log methods. 420 #define MRPT_UNSCOPED_LOGGER_END \ 423 static dummy_logger_ tmp_obj; \ 424 tmp_obj.usercode(); \ 432 struct TEnumTypeFiller<
mrpt::utils::VerbosityLevel>
434 typedef mrpt::utils::VerbosityLevel
enum_t;
435 static void fill(bimap<enum_t,std::string> &m_map)
438 m_map.insert(LVL_DEBUG,
"DEBUG");
439 m_map.insert(LVL_DEBUG,
"LVL_DEBUG");
440 m_map.insert(LVL_INFO ,
"INFO");
441 m_map.insert(LVL_INFO ,
"LVL_INFO");
442 m_map.insert(LVL_WARN ,
"WARN");
443 m_map.insert(LVL_WARN ,
"LVL_WARN");
444 m_map.insert(LVL_ERROR,
"ERROR");
445 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)
#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...
bool operator<(const CArray< T, N > &x, const CArray< T, N > &y)
TConsoleColor
For use in setConsoleColor.
CStream BASE_IMPEXP & 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
bool operator==(const CArray< T, N > &x, const CArray< T, N > &y)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red