1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/time/Time.hpp" 5 #include "hmbdc/pattern/GuardedSingleton.hpp" 9 #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__)) 10 #define HMBDC_LOG_N(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_N(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[1], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 11 #define HMBDC_LOG_W(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_W(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[2], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 12 #define HMBDC_LOG_C(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_C(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[3], __VA_ARGS__, hmbdc::app::LogTrailer(__FILE__, __LINE__)) 13 #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__)) 14 #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') 15 #define HMBDC_LOG_n(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_N(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[1], __VA_ARGS__, '\n') 16 #define HMBDC_LOG_w(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_W(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[2], __VA_ARGS__, '\n') 17 #define HMBDC_LOG_c(...) if (hmbdc::app::SyncLogger::initialized()) hmbdc::app::SyncLogger::instance().LOG_C(hmbdc::time::SysTime::now(), hmbdc::app::g_SyncLogLevelStr[3], __VA_ARGS__, '\n') 19 namespace hmbdc {
namespace app {
21 char const g_SyncLogLevelStr[][12 + 1] = {
37 friend std::ostream& operator << (std::ostream& os,
LogTrailer const& t) {
38 os <<
' ' << t.f <<
':' << t.l << std::endl;
43 friend std::ostream& operator << (std::ostream& os,
EmptyLogTrailer const&) {
66 void setMinLogLevel(Level minLevel) {
70 template <
typename ...Args>
71 void LOG_D(Args&&... args) {
73 std::lock_guard<std::recursive_mutex> g(mutex_);
74 log(std::forward<Args>(args)...);
78 template <
typename ...Args>
79 void LOG_N(Args&&... args) {
80 if (minLevel_ <= L_NOTICE) {
81 std::lock_guard<std::recursive_mutex> g(mutex_);
82 log(std::forward<Args>(args)...);
85 template <
typename ...Args>
86 void LOG_W(Args&&... args) {
87 if (minLevel_ <= L_WARNING) {
88 std::lock_guard<std::recursive_mutex> g(mutex_);
89 log(std::forward<Args>(args)...);
92 template <
typename ...Args>
93 void LOG_C(Args&&... args) {
94 if (minLevel_ <= L_CRITICAL) {
95 std::lock_guard<std::recursive_mutex> g(mutex_);
96 log(std::forward<Args>(args)...);
101 template <
typename Arg,
typename ...Args>
102 void log(Arg&& arg, Args&&... args) {
103 log_ << std::forward<Arg>(arg);
104 log(std::forward<Args>(args)...);
108 template <
typename ... NoOpArgs>
109 SyncLogger(std::ostream& log, NoOpArgs&&...)
115 std::recursive_mutex mutex_;
a very straightforward logger that works synchronisely.
Definition: Logger.hpp:54
base for the Singleton that works with SingletonGuardian
Definition: GuardedSingleton.hpp:35
RAII representing the lifespan of the underlying Singleton which also ganrantees the singularity of u...
Definition: GuardedSingleton.hpp:20
Definition: Logger.hpp:42
Definition: Logger.hpp:29