00001
00019 #ifndef RTC_SYSTEMLOGGER_H
00020 #define RTC_SYSTEMLOGGER_H
00021
00022 #include <rtm/config_rtc.h>
00023
00024
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 {
00105 RTL_SILENT,
00106 RTL_FATAL,
00107 RTL_ERROR,
00108 RTL_WARN,
00109 RTL_INFO,
00110 RTL_DEBUG,
00111 RTL_TRACE,
00112 RTL_VERBOSE,
00113 RTL_PARANOID
00114 };
00115
00134 Logger(const char* name = "");
00153 Logger(LogStreamBuf* streambuf);
00165 virtual ~Logger(void);
00166
00182 bool setLevel(const char* level);
00183
00255 void setDateFormat(const char* format);
00256
00276 void setName(const char* name);
00277
00278 protected:
00297 virtual void header(int level);
00298
00314 std::string getDate(void);
00315
00333 int strToLevel(const char* level);
00334
00335 private:
00336 std::string m_name;
00337 std::string m_dateFormat;
00338 static const char* m_levelString[];
00339 };
00340
00341
00342 #ifndef NO_LOGGING
00343
00358 #define RTC_LOG(LV, fmt) \
00359 if (rtclog.isValid(LV)) \
00360 { \
00361 std::string str = ::coil::sprintf fmt; \
00362 rtclog.lock(); \
00363 rtclog.level(LV) << str << std::endl; \
00364 rtclog.unlock(); \
00365 }
00366
00367 #define RTC_LOG_STR(LV, str) \
00368 if (rtclog.isValid(LV)) \
00369 { \
00370 rtclog.lock(); \
00371 rtclog.level(LV) << str << std::endl; \
00372 rtclog.unlock(); \
00373 }
00374
00394 #define RTC_FATAL(fmt) RTC_LOG(::RTC::Logger::RTL_FATAL, fmt)
00395 #define RTC_FATAL_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_FATAL, str)
00396
00416 #define RTC_ERROR(fmt) RTC_LOG(::RTC::Logger::RTL_ERROR, fmt)
00417 #define RTC_ERROR_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_ERROR, str)
00418
00438 #define RTC_WARN(fmt) RTC_LOG(::RTC::Logger::RTL_WARN, fmt)
00439 #define RTC_WARN_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_WARN, str)
00440
00460 #define RTC_INFO(fmt) RTC_LOG(::RTC::Logger::RTL_INFO, fmt)
00461 #define RTC_INFO_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_INFO, str)
00462
00482 #define RTC_DEBUG(fmt) RTC_LOG(::RTC::Logger::RTL_DEBUG, fmt)
00483 #define RTC_DEBUG_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, str)
00484
00504 #define RTC_TRACE(fmt) RTC_LOG(::RTC::Logger::RTL_TRACE, fmt)
00505 #define RTC_TRACE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_TRACE, str)
00506
00507
00527 #define RTC_VERBOSE(fmt) RTC_LOG(::RTC::Logger::RTL_VERBOSE, fmt)
00528 #define RTC_VERBOSE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, str)
00529
00549 #define RTC_PARANOID(fmt) RTC_LOG(::RTC::Logger::RTL_PARANOID, fmt)
00550 #define RTC_PARANOID_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, str)
00551
00552 #else
00553 #define RTC_ERROR(fmt)
00554 #define RTC_ERROR_STR(str)
00555 #define RTC_WARN(fmt)
00556 #define RTC_WARN_STR(str)
00557 #define RTC_NORMAL(fmt)
00558 #define RTC_NORMAL_STR(str)
00559 #define RTC_INFO(fmt)
00560 #define RTC_INFO_STR(str)
00561 #define RTC_DEBUG(fmt)
00562 #define RTC_DEBUG_STR(str)
00563 #define RTC_TRACE(fmt)
00564 #define RTC_TRACE_STR(str)
00565 #define RTC_VERBOSE(fmt)
00566 #define RTC_VERBOSE_STR(str)
00567 #define RTC_PARANOID(fmt)
00568 #define RTC_PARANOID_STR(str)
00569 #endif
00570
00571 };
00572
00573 #endif // RTC_SYSTEMLOGGER_H