1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/app/Base.hpp" 5 #include "hmbdc/text/LfbStream.hpp" 6 #include "hmbdc/time/Time.hpp" 11 #define HMBDC_ALOG_D(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_D(__VA_ARGS__, LogTrailer(__FILE__, __LINE__)) 12 #define HMBDC_ALOG_N(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_N(__VA_ARGS__, LogTrailer(__FILE__, __LINE__)) 13 #define HMBDC_ALOG_W(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_W(__VA_ARGS__, LogTrailer(__FILE__, __LINE__)) 14 #define HMBDC_ALOG_C(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_C(__VA_ARGS__, LogTrailer(__FILE__, __LINE__)) 15 #define HMBDC_ALOG_DEBUG(x) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_D(#x "=", x, LogTrailer(__FILE__, __LINE__)) 17 #define HMBDC_ALOG_d(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_D(__VA_ARGS__, EmptyLogTrailer()) 18 #define HMBDC_ALOG_n(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_N(__VA_ARGS__, EmptyLogTrailer()) 19 #define HMBDC_ALOG_w(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_W(__VA_ARGS__, EmptyLogTrailer()) 20 #define HMBDC_ALOG_c(...) hmbdc::app::utils::AsyncLoggerT<HMBDC_ALOG_CONTEXT>::instance().LOG_C(__VA_ARGS__, EmptyLogTrailer()) 22 namespace hmbdc {
namespace app {
namespace utils {
24 char const g_LogLevelStr[][12] = {
38 template <
typename Ctx>
40 :
Client<AsyncLoggerT<Ctx>, LoggingT<Ctx::MAX_MESSAGE_SIZE>>
42 , MessageWrap<LoggingT<Ctx::MAX_MESSAGE_SIZE>>
43 , LoggingT<Ctx::MAX_MESSAGE_SIZE>::typeTag
46 static_assert(Ctx::MAX_MESSAGE_SIZE != 0
47 ,
"HMBDC_ALOG_CONTEXT needs to be 'compile time sized'");
60 static std::unique_ptr<Ctx> pCtx_s;
63 std::string schedPolicy_;
69 AsyncLoggerT(std::ostream& log
70 , uint64_t cpuAffinityMask = 0
71 ,
char const* schedPolicy =
"SCHED_IDLE" 73 , uint16_t logBufferSizePower2Num = 8)
74 :
Stream((pCtx_s = std::unique_ptr<Ctx>(
new Ctx(logBufferSizePower2Num)))->buffer())
78 , schedPolicy_(schedPolicy)
79 , priority_(priority) {
81 , cpuAffinityMask?cpuAffinityMask:(1ul << std::thread::hardware_concurrency()) - 1ul);
91 AsyncLoggerT(std::ostream& log, Ctx& ctx
92 ,
char const* schedPolicy =
"SCHED_IDLE" 98 , schedPolicy_(schedPolicy)
99 , priority_(priority) {
105 , ts(hmbdc::time::SysTime::now()) {
111 friend std::ostream& operator << (std::ostream& os,
LogHeader const& h) {
112 os << h.ts <<
" " << g_LogLevelStr[h.l];
118 char const* hmbdcName()
const {
return "logger"; }
119 void setMinLogLevel(Level minLevel) {
120 minLevel_ = minLevel;
123 std::tuple<char const*, int> schedSpec()
const {
124 return std::make_tuple(schedPolicy_.c_str(), priority_);
127 template <
typename ...Args>
128 void LOG_D(Args&&... args) {
130 Stream::operator()(
LogHeader(L_DEBUG), std::forward<Args>(args)...);
134 template <
typename ...Args>
135 void LOG_N(Args&&... args) {
136 if (minLevel_ <= L_NOTICE)
137 Stream::operator()(
LogHeader(L_NOTICE), std::forward<Args>(args)...);
139 template <
typename ...Args>
140 void LOG_W(Args&&... args) {
141 if (minLevel_ <= L_WARNING)
142 Stream::operator()(
LogHeader(L_WARNING), std::forward<Args>(args)...);
144 template <
typename ...Args>
145 void LOG_C(Args&&... args) {
146 if (minLevel_ <= L_CRITICAL)
147 Stream::operator()(
LogHeader(L_CRITICAL), std::forward<Args>(args)...);
150 void handleMessageCb(
Logging& logItem) {
151 Stream::dump(log_, logItem);
155 template <
typename Ctx>
Definition: Message.hpp:168
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: LfbStream.hpp:82
Definition: Message.hpp:112
A Client represents a thread of execution/a task. The execution is managed by a Context. a Client object could participate in message dispatching as the receiver of specifed message types.
Definition: Client.hpp:57
a high performance async logger that doesn't penalize logging threads as much when the logging load i...
Definition: AsyncLoggerT.hpp:39