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/ClockManager.h>
00027 #include <coil/Logger.h>
00028 #include <coil/Mutex.h>
00029 #include <coil/Guard.h>
00030 #include <coil/stringutil.h>
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
00259 void setDateFormat(const char* format);
00260
00299 void setClockType(std::string clocktype);
00300
00320 void setName(const char* name);
00321
00322 protected:
00341 virtual void header(int level);
00342
00358 std::string getDate(void);
00359
00377 int strToLevel(const char* level);
00378
00379 private:
00380 std::string m_name;
00381 std::string m_dateFormat;
00382 coil::IClock* m_clock;
00383 static const char* m_levelString[];
00384 int m_msEnable;
00385 int m_usEnable;
00386 };
00387
00388
00389 #ifndef NO_LOGGING
00390
00405 #define RTC_LOG(LV, fmt) \
00406 if (rtclog.isValid(LV)) \
00407 { \
00408 std::string str = ::coil::sprintf fmt; \
00409 rtclog.lock(); \
00410 rtclog.level(LV) << str << std::endl; \
00411 rtclog.unlock(); \
00412 }
00413
00414 #define RTC_LOG_STR(LV, str) \
00415 if (rtclog.isValid(LV)) \
00416 { \
00417 rtclog.lock(); \
00418 rtclog.level(LV) << str << std::endl; \
00419 rtclog.unlock(); \
00420 }
00421
00441 #define RTC_FATAL(fmt) RTC_LOG(::RTC::Logger::RTL_FATAL, fmt)
00442 #define RTC_FATAL_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_FATAL, str)
00443
00463 #define RTC_ERROR(fmt) RTC_LOG(::RTC::Logger::RTL_ERROR, fmt)
00464 #define RTC_ERROR_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_ERROR, str)
00465
00485 #define RTC_WARN(fmt) RTC_LOG(::RTC::Logger::RTL_WARN, fmt)
00486 #define RTC_WARN_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_WARN, str)
00487
00507 #define RTC_INFO(fmt) RTC_LOG(::RTC::Logger::RTL_INFO, fmt)
00508 #define RTC_INFO_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_INFO, str)
00509
00529 #define RTC_DEBUG(fmt) RTC_LOG(::RTC::Logger::RTL_DEBUG, fmt)
00530 #define RTC_DEBUG_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, str)
00531
00551 #define RTC_TRACE(fmt) RTC_LOG(::RTC::Logger::RTL_TRACE, fmt)
00552 #define RTC_TRACE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_TRACE, str)
00553
00554
00574 #define RTC_VERBOSE(fmt) RTC_LOG(::RTC::Logger::RTL_VERBOSE, fmt)
00575 #define RTC_VERBOSE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, str)
00576
00596 #define RTC_PARANOID(fmt) RTC_LOG(::RTC::Logger::RTL_PARANOID, fmt)
00597 #define RTC_PARANOID_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, str)
00598
00599 #else
00600 #define RTC_ERROR(fmt)
00601 #define RTC_ERROR_STR(str)
00602 #define RTC_WARN(fmt)
00603 #define RTC_WARN_STR(str)
00604 #define RTC_NORMAL(fmt)
00605 #define RTC_NORMAL_STR(str)
00606 #define RTC_INFO(fmt)
00607 #define RTC_INFO_STR(str)
00608 #define RTC_DEBUG(fmt)
00609 #define RTC_DEBUG_STR(str)
00610 #define RTC_TRACE(fmt)
00611 #define RTC_TRACE_STR(str)
00612 #define RTC_VERBOSE(fmt)
00613 #define RTC_VERBOSE_STR(str)
00614 #define RTC_PARANOID(fmt)
00615 #define RTC_PARANOID_STR(str)
00616 #endif
00617
00618 };
00619
00620 #endif // RTC_SYSTEMLOGGER_H