19 #ifndef RTC_SYSTEMLOGGER_H
20 #define RTC_SYSTEMLOGGER_H
22 #include <rtm/config_rtc.h>
24 #include <coil/ClockManager.h>
25 #include <coil/Logger.h>
27 #include <coil/stringutil.h>
28 #include <coil/Properties.h>
346 void write(
int level,
const std::string &mes)
override;
396 return m_levelString[level];
423 return m_levelOutputString[level];
451 return m_levelColor[level];
497 std::string m_name =
"unknown";
498 std::string m_dateFormat =
"%b %d %H:%M:%S.%Q";
499 coil::IClock* m_clock{&coil::ClockManager::instance().getClock(
"system")};
501 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
502 #ifdef LIBRARY_EXPORTS
503 static __declspec(dllexport)
const char*
const m_levelString[];
504 static __declspec(dllexport)
const char*
const m_levelOutputString[];
505 static __declspec(dllexport)
const char*
const m_levelColor[];
507 static __declspec(dllimport)
const char*
const m_levelString[];
508 static __declspec(dllimport)
const char*
const m_levelOutputString[];
509 static __declspec(dllimport)
const char*
const m_levelColor[];
512 static const char*
const m_levelString[];
513 static const char*
const m_levelOutputString[];
514 static const char*
const m_levelColor[];
516 bool m_msEnable{
false};
517 bool m_usEnable{
false};
537 #define RTC_LOG(LV, fmt) \
539 if (rtclog.isValid(LV)) \
541 std::string str = ::coil::sprintf fmt; \
543 rtclog.write(LV, str); \
548 #define RTC_LOG_STR(LV, str) \
550 if (rtclog.isValid(LV)) \
553 rtclog.write(LV, str); \
577 #define RTC_FATAL(fmt) RTC_LOG(::RTC::Logger::RTL_FATAL, fmt)
578 #define RTC_FATAL_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_FATAL, str)
599 #define RTC_ERROR(fmt) RTC_LOG(::RTC::Logger::RTL_ERROR, fmt)
600 #define RTC_ERROR_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_ERROR, str)
621 #define RTC_WARN(fmt) RTC_LOG(::RTC::Logger::RTL_WARN, fmt)
622 #define RTC_WARN_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_WARN, str)
643 #define RTC_INFO(fmt) RTC_LOG(::RTC::Logger::RTL_INFO, fmt)
644 #define RTC_INFO_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_INFO, str)
665 #define RTC_DEBUG(fmt) RTC_LOG(::RTC::Logger::RTL_DEBUG, fmt)
666 #define RTC_DEBUG_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, str)
687 #define RTC_TRACE(fmt) RTC_LOG(::RTC::Logger::RTL_TRACE, fmt)
688 #define RTC_TRACE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_TRACE, str)
710 #define RTC_VERBOSE(fmt) RTC_LOG(::RTC::Logger::RTL_VERBOSE, fmt)
711 #define RTC_VERBOSE_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, str)
732 #define RTC_PARANOID(fmt) RTC_LOG(::RTC::Logger::RTL_PARANOID, fmt)
733 #define RTC_PARANOID_STR(str) RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, str)
736 #define RTC_FATAL(fmt)
737 #define RTC_FATAL_STR(str)
738 #define RTC_ERROR(fmt)
739 #define RTC_ERROR_STR(str)
740 #define RTC_WARN(fmt)
741 #define RTC_WARN_STR(str)
742 #define RTC_INFO(fmt)
743 #define RTC_INFO_STR(str)
744 #define RTC_DEBUG(fmt)
745 #define RTC_DEBUG_STR(str)
746 #define RTC_TRACE(fmt)
747 #define RTC_TRACE_STR(str)
748 #define RTC_VERBOSE(fmt)
749 #define RTC_VERBOSE_STR(str)
750 #define RTC_PARANOID(fmt)
751 #define RTC_PARANOID_STR(str)
752 #define RTC_FATAL(fmt)
753 #define RTC_FATAL_STR(str)
Logger class.
Definition: SystemLogger.h:101
static std::string getLevelColor(int level)
Definition: SystemLogger.h:449
Logger(LogStreamBuf *streambuf)
Constructor.
static int strToLevel(const char *level)
Set the log level Set the log level corresponding to the given string.
@ RTL_INFO
Definition: SystemLogger.h:109
@ RTL_DEBUG
Definition: SystemLogger.h:110
@ RTL_SILENT
Definition: SystemLogger.h:105
@ RTL_WARN
Definition: SystemLogger.h:108
@ RTL_FATAL
Definition: SystemLogger.h:106
@ RTL_VERBOSE
Definition: SystemLogger.h:112
@ RTL_ERROR
Definition: SystemLogger.h:107
@ RTL_PARANOID
Definition: SystemLogger.h:113
@ RTL_TRACE
Definition: SystemLogger.h:111
void setName(const char *name)
Set suffix of date/time string of header.
void write(int level, const std::string &mes) override
log output
void setDateFormat(const char *format)
Set date/time format for adding the header.
void write(int level, const coil::Properties &prop)
log output
std::string getDate()
Get the current formatted date/time string Get the current datetime described by specified format.
void setClockType(const std::string &clocktype)
Specifying clock type to be used for logging.
static std::string getLevelString(int level)
Definition: SystemLogger.h:394
~Logger() override
Virtual destructor.
Logger(const char *name="")
Constructor.
bool setLevel(const char *level)
Set log level by string.
static std::string getLevelOutputString(int level)
Definition: SystemLogger.h:421
::coil::LogStream LogStream
Definition: SystemLogger.h:35
coil::Properties Properties
Definition: RTC.h:72
::coil::LogStreamBuffer LogStreamBuf
Definition: SystemLogger.h:34