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_d(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_D(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[0], __VA_ARGS__, '\n')
24 #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')
25 #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')
26 #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')
28 #define HMBDC_LOG_ONCE(...) {static bool done = false; if (!done) {done = true; {__VA_ARGS__}}}
30 namespace hmbdc {
namespace app {
32 char const g_SyncLogLevelStr[][12 + 1] = {
49 friend std::ostream& operator << (std::ostream& os,
LogTrailer const& t) {
50 os <<
' ' << t.f <<
':' << t.l << std::endl;
55 friend std::ostream& operator << (std::ostream& os,
EmptyLogTrailer const&) {
79 void setMinLogLevel(Level minLevel) {
83 template <
typename ...Args>
84 void LOG_D(Args&&... args) {
86 std::lock_guard<std::recursive_mutex> g(mutex_);
87 log(std::forward<Args>(args)...);
91 template <
typename ...Args>
92 void LOG_R(Args&&... args) {
93 #ifdef HMBDC_RUNTIME_DEBUG
94 if (minLevel_ <= L_RDEBUG) {
95 std::lock_guard<std::recursive_mutex> g(mutex_);
96 log(std::forward<Args>(args)...);
101 template <
typename ...Args>
102 void LOG_N(Args&&... args) {
103 if (minLevel_ <= L_NOTICE) {
104 std::lock_guard<std::recursive_mutex> g(mutex_);
105 log(std::forward<Args>(args)...);
108 template <
typename ...Args>
109 void LOG_W(Args&&... args) {
110 if (minLevel_ <= L_WARNING) {
111 std::lock_guard<std::recursive_mutex> g(mutex_);
112 log(std::forward<Args>(args)...);
115 template <
typename ...Args>
116 void LOG_C(Args&&... args) {
117 if (minLevel_ <= L_CRITICAL) {
118 std::lock_guard<std::recursive_mutex> g(mutex_);
119 log(std::forward<Args>(args)...);
124 template <
typename Arg,
typename ...Args>
125 void log(Arg&& arg, Args&&... args) {
126 log_ << std::forward<Arg>(arg);
127 log(std::forward<Args>(args)...);
131 template <
typename ... NoOpArgs>
132 SyncLogger(std::ostream& log, NoOpArgs&&...)
137 , minLevel_(L_NOTICE)
142 std::recursive_mutex mutex_;
a very straightforward logger that works synchronisely.
Definition: Logger.hpp:66
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:54
Definition: Logger.hpp:41