SystemLogger.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef RTC_SYSTEMLOGGER_H
20 #define RTC_SYSTEMLOGGER_H
21 
22 #include <rtm/config_rtc.h>
23 
24 // COIL
25 #include <coil/Time.h>
26 #include <coil/Logger.h>
27 #include <coil/Mutex.h>
28 #include <coil/Guard.h>
29 #include <coil/stringutil.h>
30 
31 
32 namespace RTC
33 {
36 
99  class Logger
100  : public coil::LogStream
101  {
102  public:
103  enum
104  { // No: Write out messages include the following.
105  RTL_SILENT, // 0: ()
106  RTL_FATAL, // 1: (FATAL)
107  RTL_ERROR, // 2: (FATAL, ERROR)
108  RTL_WARN, // 3: (FATAL, ERROR, WARN)
109  RTL_INFO, // 4: (FATAL, ERROR, WARN, INFO)
110  RTL_DEBUG, // 5: (FATAL, ERROR, WARN, INFO, DEBUG)
111  RTL_TRACE, // 6: (FATAL, ERROR, WARN, INFO, DEBUG, TRACE)
112  RTL_VERBOSE, // 7: (FATAL, ERROR, WARN, INFO, DEBUG, TRACE, VERBOSE)
113  RTL_PARANOID // 8: (FATAL, ERROR, WARN, INFO, DEBUG, TRACE, VERBOSE, PARA)
114  };
115 
134  Logger(const char* name = "");
153  Logger(LogStreamBuf* streambuf);
165  virtual ~Logger(void);
166 
182  bool setLevel(const char* level);
183 
259  void setDateFormat(const char* format);
260 
280  void setName(const char* name);
281 
282  protected:
301  virtual void header(int level);
302 
318  std::string getDate(void);
319 
337  int strToLevel(const char* level);
338 
339  private:
340  std::string m_name;
341  std::string m_dateFormat;
342  static const char* m_levelString[];
345  };
346 
347 
348 #ifndef NO_LOGGING
349 
364 #define RTC_LOG(LV, fmt) \
365  if (rtclog.isValid(LV)) \
366  { \
367  std::string str = ::coil::sprintf fmt; \
368  rtclog.lock(); \
369  rtclog.level(LV) << str << std::endl; \
370  rtclog.unlock(); \
371  }
372 
373 #define RTC_LOG_STR(LV, str) \
374  if (rtclog.isValid(LV)) \
375  { \
376  rtclog.lock(); \
377  rtclog.level(LV) << str << std::endl; \
378  rtclog.unlock(); \
379  }
380 
400 #define RTC_FATAL(fmt) RTC_LOG(::RTC::Logger::RTL_FATAL, fmt)
401 #define RTC_FATAL_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_FATAL, str)
402 
422 #define RTC_ERROR(fmt) RTC_LOG(::RTC::Logger::RTL_ERROR, fmt)
423 #define RTC_ERROR_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_ERROR, str)
424 
444 #define RTC_WARN(fmt) RTC_LOG(::RTC::Logger::RTL_WARN, fmt)
445 #define RTC_WARN_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_WARN, str)
446 
466 #define RTC_INFO(fmt) RTC_LOG(::RTC::Logger::RTL_INFO, fmt)
467 #define RTC_INFO_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_INFO, str)
468 
488 #define RTC_DEBUG(fmt) RTC_LOG(::RTC::Logger::RTL_DEBUG, fmt)
489 #define RTC_DEBUG_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, str)
490 
510 #define RTC_TRACE(fmt) RTC_LOG(::RTC::Logger::RTL_TRACE, fmt)
511 #define RTC_TRACE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_TRACE, str)
512 
513 
533 #define RTC_VERBOSE(fmt) RTC_LOG(::RTC::Logger::RTL_VERBOSE, fmt)
534 #define RTC_VERBOSE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, str)
535 
555 #define RTC_PARANOID(fmt) RTC_LOG(::RTC::Logger::RTL_PARANOID, fmt)
556 #define RTC_PARANOID_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, str)
557 
558 #else
559 #define RTC_ERROR(fmt)
560 #define RTC_ERROR_STR(str)
561 #define RTC_WARN(fmt)
562 #define RTC_WARN_STR(str)
563 #define RTC_NORMAL(fmt)
564 #define RTC_NORMAL_STR(str)
565 #define RTC_INFO(fmt)
566 #define RTC_INFO_STR(str)
567 #define RTC_DEBUG(fmt)
568 #define RTC_DEBUG_STR(str)
569 #define RTC_TRACE(fmt)
570 #define RTC_TRACE_STR(str)
571 #define RTC_VERBOSE(fmt)
572 #define RTC_VERBOSE_STR(str)
573 #define RTC_PARANOID(fmt)
574 #define RTC_PARANOID_STR(str)
575 #endif
576 
577 }; // namespace RTC
578 
579 #endif // RTC_SYSTEMLOGGER_H
void setDateFormat(const char *format)
Set date/time format for adding the header.
virtual ~Logger(void)
Virtual destructor.
virtual void header(int level)
Message prefix appender function.
RT-Component.
::coil::LogStreamBuffer LogStreamBuf
Definition: SystemLogger.h:34
::coil::LogStream LogStream
Definition: SystemLogger.h:35
void setName(const char *name)
Set suffix of date/time string of header.
log_stream template class
log_streambuf< char > LogStreamBuffer
bool setLevel(const char *level)
Set log level by string.
ostream_type & level(int level)
Acquire log stream.
std::string m_dateFormat
Definition: SystemLogger.h:341
std::string m_name
Definition: SystemLogger.h:340
Logger(const char *name="")
Constructor.
int strToLevel(const char *level)
Set the log level Set the log level corresponding to the given string.
static const char * m_levelString[]
Definition: SystemLogger.h:342
std::string getDate(void)
Get the current formatted date/time string Get the current datetime described by specified format...


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00