1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/time/Time.hpp" 5 #include "hmbdc/pattern/GuardedSingleton.hpp" 10 #ifdef HMBDC_RUNTIME_DEBUG 11 #define HMBDC_LOG_R(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_R(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[1], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 12 #define HMBDC_LOG_r(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_R(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[1], __VA_ARGS__, '\n') 14 #define HMBDC_LOG_R(...) 15 #define HMBDC_LOG_r(...) 18 #define HMBDC_LOG_D(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_D(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[0], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 19 #define HMBDC_LOG_N(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_N(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[2], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 20 #define HMBDC_LOG_W(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_W(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[3], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 21 #define HMBDC_LOG_C(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_C(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[4], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 22 #define HMBDC_LOG_DEBUG(x) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_D(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[0], #x "=", x, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 23 #define HMBDC_LOG_NOTICE(x) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_N(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[2], #x "=", x, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 24 #define HMBDC_LOG_WARNING(x) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_N(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[3], #x "=", x, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 25 #define HMBDC_LOG_CRITICAL(x) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_N(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[4], #x "=", x, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 26 #define HMBDC_LOG_d(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_D(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[0], __VA_ARGS__, '\n') 27 #define HMBDC_LOG_n(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_N(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[2], __VA_ARGS__, '\n') 28 #define HMBDC_LOG_w(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_W(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[3], __VA_ARGS__, '\n') 29 #define HMBDC_LOG_c(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_C(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[4], __VA_ARGS__, '\n') 31 #define HMBDC_LOG_ONCE(...) {static bool done = false; if (!done) {done = true; {__VA_ARGS__}}} 33 namespace hmbdc {
namespace app {
35 char const g_SyncLogLevelStr[][12 + 1] = {
52 friend std::ostream& operator << (std::ostream& os,
LogTrailer const& t) {
53 os <<
' ' << t.f <<
':' << t.l << std::endl;
58 friend std::ostream& operator << (std::ostream& os,
EmptyLogTrailer const&) {
82 void setMinLogLevel(Level minLevel) {
86 template <
typename ...Args>
87 void LOG_D(Args&&... args) {
89 if (minLevel_ <= L_DEBUG) {
90 std::lock_guard<std::recursive_mutex> g(mutex_);
91 log(std::forward<Args>(args)...);
96 template <
typename ...Args>
97 void LOG_R(Args&&... args) {
98 #ifdef HMBDC_RUNTIME_DEBUG 99 if (minLevel_ <= L_RDEBUG) {
100 std::lock_guard<std::recursive_mutex> g(mutex_);
101 log(std::forward<Args>(args)...);
106 template <
typename ...Args>
107 void LOG_N(Args&&... args) {
108 if (minLevel_ <= L_NOTICE) {
109 std::lock_guard<std::recursive_mutex> g(mutex_);
110 log(std::forward<Args>(args)...);
113 template <
typename ...Args>
114 void LOG_W(Args&&... args) {
115 if (minLevel_ <= L_WARNING) {
116 std::lock_guard<std::recursive_mutex> g(mutex_);
117 log(std::forward<Args>(args)...);
120 template <
typename ...Args>
121 void LOG_C(Args&&... args) {
122 if (minLevel_ <= L_CRITICAL) {
123 std::lock_guard<std::recursive_mutex> g(mutex_);
124 log(std::forward<Args>(args)...);
129 template <
typename Arg,
typename ...Args>
130 void log(Arg&& arg, Args&&... args) {
131 log_ << std::forward<Arg>(arg);
132 log(std::forward<Args>(args)...);
136 template <
typename ... NoOpArgs>
142 , minLevel_(L_NOTICE)
147 std::recursive_mutex mutex_;
a very straightforward logger that works synchronisely.
Definition: Logger.hpp:69
base for the Singleton that works with SingletonGuardian
Definition: GuardedSingleton.hpp:53
RAII representing the lifespan of the underlying Singleton which also ganrantees the singularity of u...
Definition: GuardedSingleton.hpp:20
Definition: Logger.hpp:57
Definition: Logger.hpp:44