00001
00019 #ifndef SystemLogger_h
00020 #define 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
00037 class Logger
00038 : public coil::LogStream
00039 {
00040 public:
00041 enum
00042 {
00043 RTL_SILENT,
00044 RTL_FATAL,
00045 RTL_ERROR,
00046 RTL_WARN,
00047 RTL_INFO,
00048 RTL_DEBUG,
00049 RTL_TRACE,
00050 RTL_VERBOSE,
00051 RTL_PARANOID
00052 };
00053
00054 Logger(const char* name = "");
00055 Logger(LogStreamBuf* streambuf);
00056 virtual ~Logger(void);
00057
00073 bool setLevel(const char* level);
00074
00146 void setDateFormat(const char* format);
00147
00167 void setName(const char* name);
00168
00169 protected:
00188 virtual void header(int level);
00189
00205 std::string getDate(void);
00206
00224 int strToLevel(const char* level);
00225
00226 private:
00227 std::string m_name;
00228 std::string m_dateFormat;
00229 static const char* m_levelString[];
00230 };
00231
00232
00233 #ifndef NO_LOGGING
00234
00249 #define RTC_LOG(LV, fmt) \
00250 if (rtclog.isValid(LV)) \
00251 { \
00252 rtclog.lock(); \
00253 rtclog.level(LV) << ::coil::sprintf fmt << std::endl; \
00254 rtclog.unlock(); \
00255 }
00256
00257 #define RTC_LOG_STR(LV, str) \
00258 if (rtclog.isValid(LV)) \
00259 { \
00260 rtclog.lock(); \
00261 rtclog.level(LV) << str << std::endl; \
00262 rtclog.unlock(); \
00263 }
00264
00284 #define RTC_FATAL(fmt) RTC_LOG(::RTC::Logger::RTL_FATAL, fmt)
00285 #define RTC_FATAL_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_FATAL, str)
00286
00306 #define RTC_ERROR(fmt) RTC_LOG(::RTC::Logger::RTL_ERROR, fmt)
00307 #define RTC_ERROR_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_ERROR, str)
00308
00328 #define RTC_WARN(fmt) RTC_LOG(::RTC::Logger::RTL_WARN, fmt)
00329 #define RTC_WARN_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_WARN, str)
00330
00350 #define RTC_INFO(fmt) RTC_LOG(::RTC::Logger::RTL_INFO, fmt)
00351 #define RTC_INFO_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_INFO, str)
00352
00372 #define RTC_DEBUG(fmt) RTC_LOG(::RTC::Logger::RTL_DEBUG, fmt)
00373 #define RTC_DEBUG_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, str)
00374
00394 #define RTC_TRACE(fmt) RTC_LOG(::RTC::Logger::RTL_TRACE, fmt)
00395 #define RTC_TRACE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_TRACE, str)
00396
00397
00417 #define RTC_VERBOSE(fmt) RTC_LOG(::RTC::Logger::RTL_VERBOSE, fmt)
00418 #define RTC_VERBOSE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, str)
00419
00439 #define RTC_PARANOID(fmt) RTC_LOG(::RTC::Logger::RTL_PARANOID, fmt)
00440 #define RTC_PARANOID_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, str)
00441
00442 #else
00443 #define RTC_ERROR(fmt)
00444 #define RTC_ERROR_STR(str)
00445 #define RTC_WARN(fmt)
00446 #define RTC_WARN_STR(str)
00447 #define RTC_NORMAL(fmt)
00448 #define RTC_NORMAL_STR(str)
00449 #define RTC_INFO(fmt)
00450 #define RTC_INFO_STR(str)
00451 #define RTC_DEBUG(fmt)
00452 #define RTC_DEBUG_STR(str)
00453 #define RTC_TRACE(fmt)
00454 #define RTC_TRACE_STR(str)
00455 #define RTC_VERBOSE(fmt)
00456 #define RTC_VERBOSE_STR(str)
00457 #define RTC_PARANOID(fmt)
00458 #define RTC_PARANOID_STR(str)
00459 #endif
00460
00461 };
00462
00463 #endif // SystemLogger_h