SystemLogger.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #ifndef RTC_SYSTEMLOGGER_H
00020 #define RTC_SYSTEMLOGGER_H
00021 
00022 #include <rtm/config_rtc.h>
00023 
00024 // COIL
00025 #include <coil/Time.h>
00026 #include <coil/Logger.h>
00027 #include <coil/Mutex.h>
00028 #include <coil/Guard.h>
00029 #include <coil/stringutil.h>
00030 
00031 
00032 namespace RTC
00033 {
00034   typedef ::coil::LogStreamBuffer LogStreamBuf;
00035   typedef ::coil::LogStream LogStream;
00036 
00099   class Logger
00100     : public coil::LogStream
00101   {
00102   public:
00103     enum
00104       {              // No: Write out messages include the following.
00105         RTL_SILENT,  // 0: ()
00106         RTL_FATAL,   // 1: (FATAL)
00107         RTL_ERROR,   // 2: (FATAL, ERROR)
00108         RTL_WARN,    // 3: (FATAL, ERROR, WARN)
00109         RTL_INFO,    // 4: (FATAL, ERROR, WARN, INFO)
00110         RTL_DEBUG,   // 5: (FATAL, ERROR, WARN, INFO, DEBUG)
00111         RTL_TRACE,   // 6: (FATAL, ERROR, WARN, INFO, DEBUG, TRACE)
00112         RTL_VERBOSE, // 7: (FATAL, ERROR, WARN, INFO, DEBUG, TRACE, VERBOSE)
00113         RTL_PARANOID // 8: (FATAL, ERROR, WARN, INFO, DEBUG, TRACE, VERBOSE, PARA)
00114       };
00115  
00134     Logger(const char* name = "");
00153     Logger(LogStreamBuf* streambuf);
00165     virtual ~Logger(void);
00166 
00182     bool setLevel(const char* level);
00183 
00259     void setDateFormat(const char* format);
00260     
00280     void setName(const char* name);
00281 
00282   protected:
00301     virtual void header(int level);
00302 
00318     std::string getDate(void);
00319 
00337     int strToLevel(const char* level);
00338 
00339   private:
00340     std::string m_name;
00341     std::string m_dateFormat;
00342     static const char* m_levelString[];
00343     int m_msEnable;
00344     int m_usEnable;
00345   };    
00346 
00347 
00348 #ifndef NO_LOGGING
00349 
00364 #define RTC_LOG(LV, fmt)                                    \
00365   if (rtclog.isValid(LV))                                   \
00366     {                                                       \
00367       std::string str = ::coil::sprintf fmt;                \
00368       rtclog.lock();                                        \
00369       rtclog.level(LV) << str << std::endl; \
00370       rtclog.unlock();                                      \
00371     }
00372 
00373 #define RTC_LOG_STR(LV, str)                                \
00374   if (rtclog.isValid(LV))                                   \
00375     {                                                       \
00376       rtclog.lock();                                        \
00377       rtclog.level(LV) << str << std::endl;  \
00378       rtclog.unlock();                                      \
00379     }
00380 
00400 #define RTC_FATAL(fmt) RTC_LOG(::RTC::Logger::RTL_FATAL, fmt)
00401 #define RTC_FATAL_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_FATAL, str)
00402  
00422 #define RTC_ERROR(fmt) RTC_LOG(::RTC::Logger::RTL_ERROR, fmt)
00423 #define RTC_ERROR_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_ERROR, str)
00424   
00444 #define RTC_WARN(fmt) RTC_LOG(::RTC::Logger::RTL_WARN, fmt)
00445 #define RTC_WARN_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_WARN, str)
00446   
00466 #define RTC_INFO(fmt) RTC_LOG(::RTC::Logger::RTL_INFO, fmt)
00467 #define RTC_INFO_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_INFO, str)
00468 
00488 #define RTC_DEBUG(fmt) RTC_LOG(::RTC::Logger::RTL_DEBUG, fmt)
00489 #define RTC_DEBUG_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, str)
00490   
00510 #define RTC_TRACE(fmt) RTC_LOG(::RTC::Logger::RTL_TRACE, fmt)
00511 #define RTC_TRACE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_TRACE, str)
00512 
00513 
00533 #define RTC_VERBOSE(fmt) RTC_LOG(::RTC::Logger::RTL_VERBOSE, fmt)
00534 #define RTC_VERBOSE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, str)
00535   
00555 #define RTC_PARANOID(fmt) RTC_LOG(::RTC::Logger::RTL_PARANOID, fmt)
00556 #define RTC_PARANOID_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, str)
00557   
00558 #else
00559 #define RTC_ERROR(fmt)
00560 #define RTC_ERROR_STR(str)
00561 #define RTC_WARN(fmt)
00562 #define RTC_WARN_STR(str)
00563 #define RTC_NORMAL(fmt)
00564 #define RTC_NORMAL_STR(str)
00565 #define RTC_INFO(fmt)
00566 #define RTC_INFO_STR(str)
00567 #define RTC_DEBUG(fmt)
00568 #define RTC_DEBUG_STR(str)
00569 #define RTC_TRACE(fmt)
00570 #define RTC_TRACE_STR(str)
00571 #define RTC_VERBOSE(fmt)
00572 #define RTC_VERBOSE_STR(str)
00573 #define RTC_PARANOID(fmt)
00574 #define RTC_PARANOID_STR(str)
00575 #endif
00576   
00577 }; // namespace RTC
00578 
00579 #endif  // RTC_SYSTEMLOGGER_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:39