ZeroErr
载入中...
搜索中...
未找到
log.h
浏览该文件的文档.
1#pragma once
2
3// libc++ offers compatibility-only transitive includes through C++20.
4// Suppress those while loading our explicit dependencies, then restore the
5// caller's setting. This does not change standard-library types or ABI.
6#pragma push_macro("_LIBCPP_REMOVE_TRANSITIVE_INCLUDES")
7#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
8#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
9#endif
10
12
15
16#include "zeroerr/dbg.h"
17#include "zeroerr/format.h"
18#include "zeroerr/print.h"
19
21#include <iosfwd>
22#include <map>
23#include "zeroerr/string.h"
24#include <utility>
25#include <vector>
26
28
29extern const char* ZEROERR_LOG_CATEGORY;
30
31namespace zeroerr {
32
33// clang-format off
34#define ZEROERR_INFO(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_INFO_(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
35#define ZEROERR_LOG(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(LOG_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
36#define ZEROERR_WARN(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(WARN_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
37#define ZEROERR_ERROR(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(ERROR_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
38#define ZEROERR_FATAL(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(FATAL_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
39// clang-format on
40
41#ifdef ZEROERR_USE_SHORT_LOG_MACRO
42
43#ifdef INFO
44#undef INFO
45#endif
46
47#ifdef LOG
48#undef LOG
49#endif
50
51#ifdef WARN
52#undef WARN
53#endif
54
55#ifdef ERR
56#undef ERR
57#endif
58
59#ifdef FATAL
60#undef FATAL
61#endif
62
63#ifdef VERBOSE
64#undef VERBOSE
65#endif
66
67#define INFO(...) ZEROERR_INFO(__VA_ARGS__)
68#define LOG(...) ZEROERR_LOG(__VA_ARGS__)
69#define WARN(...) ZEROERR_WARN(__VA_ARGS__)
70#define ERR(...) ZEROERR_ERROR(__VA_ARGS__)
71#define FATAL(...) ZEROERR_FATAL(__VA_ARGS__)
72#define VERBOSE(v) ZEROERR_VERBOSE(v)
73
74#define LOG_GET(func, id, name, type) ZEROERR_LOG_GET(func, id, name, type)
75
76#endif // ZEROERR_USE_SHORT_LOG_MACRO
77
78#define ZEROERR_LOG_IF(condition, ACTION, ...) \
79 do { \
80 if (condition) ACTION(__VA_ARGS__); \
81 } while (0)
82
83
84#define INFO_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_INFO, __VA_ARGS__)
85#define LOG_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_LOG, __VA_ARGS__)
86#define WARN_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_WARN, __VA_ARGS__)
87#define ERR_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_ERROR, __VA_ARGS__)
88#define FATAL_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_FATAL, __VA_ARGS__)
89
90
91#define ZEROERR_LOG_EVERY_(n, ACTION, ...) \
92 do { \
93 static unsigned counter = 0; \
94 if (counter == 0) { \
95 counter = n; \
96 ACTION(__VA_ARGS__); \
97 } \
98 --counter; \
99 } while (0)
100
101
102#define INFO_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_INFO, __VA_ARGS__)
103#define LOG_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_LOG, __VA_ARGS__)
104#define WARN_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_WARN, __VA_ARGS__)
105#define ERR_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_ERROR, __VA_ARGS__)
106#define FATAL_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_FATAL, __VA_ARGS__)
107
108
109#define ZEROERR_LOG_IF_EVERY_(n, cond, ACTION, ...) \
110 do { \
111 if (cond) { \
112 static unsigned counter = 0; \
113 if (counter == 0) { \
114 counter = n; \
115 ACTION(__VA_ARGS__); \
116 } \
117 --counter; \
118 } \
119 } while (0)
120
121#define INFO_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_INFO, __VA_ARGS__)
122#define LOG_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_LOG, __VA_ARGS__)
123#define WARN_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_WARN, __VA_ARGS__)
124#define ERR_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
125#define FATAL_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_FATAL, __VA_ARGS__)
126
127#define ZEROERR_LOG_FIRST(cond, ACTION, ...) \
128 do { \
129 static bool first = true; \
130 if (first && (cond)) { \
131 first = false; \
132 ACTION(__VA_ARGS__); \
133 } \
134 } while (0)
135
136#define INFO_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_INFO, __VA_ARGS__)
137#define LOG_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_LOG, __VA_ARGS__)
138#define WARN_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_WARN, __VA_ARGS__)
139#define ERR_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_ERROR, __VA_ARGS__)
140#define FATAL_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_FATAL, __VA_ARGS__)
141
142#define ZEROERR_LOG_FIRST_(n, cond, ACTION, ...) \
143 do { \
144 static unsigned counter = n; \
145 if (counter && (cond)) { \
146 counter--; \
147 ACTION(__VA_ARGS__); \
148 } \
149 } while (0)
150
151#define INFO_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_INFO, __VA_ARGS__)
152#define LOG_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_LOG, __VA_ARGS__)
153#define WARN_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_WARN, __VA_ARGS__)
154#define ERR_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
155#define FATAL_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_FATAL, __VA_ARGS__)
156
157#ifdef _DEBUG
158#define DLOG(ACTION, ...) ZEROERR_EXPAND(ACTION(__VA_ARGS__))
159#else
160#define DLOG(ACTION, ...)
161#endif
162
163extern int _ZEROERR_G_VERBOSE;
164
165#define ZEROERR_VERBOSE(v) if (zeroerr::_ZEROERR_G_VERBOSE >= (v))
166
167#define ZEROERR_LOG_(severity, message, ...) \
168 do { \
169 ZEROERR_G_CONTEXT_SCOPE(true); \
170 auto msg = zeroerr::log(__VA_ARGS__); \
171 \
172 static zeroerr::LogInfo log_info{__FILE__, \
173 __func__, \
174 message, \
175 ZEROERR_LOG_CATEGORY, \
176 __LINE__, \
177 msg.size, \
178 zeroerr::LogSeverity::severity}; \
179 msg.log->info = &log_info; \
180 if (msg.stream.getFlushMode() == zeroerr::LogStream::FlushMode::FLUSH_AT_ONCE) \
181 msg.stream.flush(); \
182 } while (0)
183
184#define ZEROERR_INFO_(...) \
185 ZEROERR_INFO_IMPL(ZEROERR_NAMEGEN(_capture_), ZEROERR_NAMEGEN(_capture_), __VA_ARGS__)
186
187#define ZEROERR_INFO_IMPL(mb_name, v_name, ...) \
188 auto v_name = zeroerr::MakeContextScope([&](zeroerr::StringBuffer& _capture_name) { \
189 zeroerr::Printer print(_capture_name); \
190 print.isQuoted = false; \
191 print(__VA_ARGS__); \
192 })
193
194#ifdef ZEROERR_G_CONTEXT_SCOPE
195#undef ZEROERR_G_CONTEXT_SCOPE
196#endif
197
198#define ZEROERR_G_CONTEXT_SCOPE(x) \
199 if (x) { \
200 for (auto* zeroerr_context_scope : zeroerr::_ZEROERR_G_CONTEXT_SCOPE_VECTOR) { \
201 zeroerr_context_scope->str(zeroerr::getStderrPrinter().os); \
202 } \
203 }
204
205#ifdef ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER
206#undef ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER
207#endif
208
209#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER(cond, level, ...) \
210 ZEROERR_LOG_IF(cond, level, __VA_ARGS__)
211
212
213// This macro can access the log in memory
214#define ZEROERR_LOG_GET(func, id, name, type) \
215 zeroerr::LogStream::getDefault().getLog<type>(#func, id, #name)
216
217
218namespace detail {
219
220template <typename T, unsigned... I>
221zeroerr::String gen_str(const char* msg, const T& args, seq<I...>) {
222 return format(msg, std::get<I>(args)...);
223}
224
225template <typename T>
226zeroerr::String gen_str(const char* msg, const T&, seq<>) {
227 return msg;
228}
229
230} // namespace detail
231
232
234 INFO_l, // it will not write to file if no other log related
238 FATAL_l, // it will contain a stack trace
239};
240
266struct LogInfo {
267 const char* filename;
268 const char* function;
269 const char* message;
270 const char* category;
271 unsigned line;
272 unsigned size;
274 std::map<zeroerr::String, int> names;
275
276 LogInfo(const char* filename, const char* function, const char* message, const char* category,
277 unsigned line, unsigned size, LogSeverity severity);
278};
279
280struct LogMessage;
281typedef zeroerr::String (*LogCustomCallback)(const LogMessage&, bool colorful);
282
286extern void setLogLevel(LogSeverity level);
287
291extern void setLogCategory(const char* categories);
292
296extern void setLogCustomCallback(LogCustomCallback callback);
297
301extern void suspendLog();
302
306extern void resumeLog();
307
317 // time is assigned when the log message is created
318 LogMessage();
319
320 // convert the log message to a string
321 virtual zeroerr::String str() const = 0;
322
323 // get the raw data pointer of the field with the name
324 virtual void* getRawLog(zeroerr::String name) const = 0;
325
326 // a map of the data indexing by the field name
327 // for example: log("print {i}", 1);
328 // a map of {"i": "1"} will be returned
329 virtual std::map<zeroerr::String, zeroerr::String> getData() const = 0;
330
331 // meta data of this log message
332 const LogInfo* info;
333
334 // recorded wall time
336};
337
338
345template <typename... T>
347 std::tuple<T...> args;
348 LogMessageImpl(T... args) : LogMessage(), args(std::move(args)...) {}
349
350 zeroerr::String str() const override {
351 return gen_str(info->message, args, detail::gen_seq<sizeof...(T)>{});
352 }
353
354 // This is a helper class to get the raw pointer of the tuple
355 struct GetTuplePtr {
356 void* ptr = nullptr;
357 template <typename H>
358 void operator()(H& v) {
359 ptr = (void*)&v;
360 }
361 };
362
363 void* getRawLog(zeroerr::String name) const override {
364 GetTuplePtr f;
365 detail::visit_at(args, info->names.at(name), f);
366 return f.ptr;
367 }
368
370 std::map<zeroerr::String, zeroerr::String> data;
373
375 print.isCompact = true;
376 print.line_break = "";
377 }
378
379 template <typename H>
380 void operator()(H& v) {
381 data[name] = print(v);
382 }
383 };
384
385 std::map<zeroerr::String, zeroerr::String> getData() const override {
386 PrintTupleData printer;
387 for (auto it = info->names.begin(); it != info->names.end(); ++it) {
388 printer.name = it->first;
389 detail::visit_at(args, it->second, printer);
390 }
391 return printer.data;
392 }
393};
394
395struct DataBlock;
396class LogStream;
397
398class Logger {
399public:
400 virtual ~Logger() = default;
401 virtual void flush(DataBlock*) = 0;
402};
403
409
429public:
430 LogIterator() : p(nullptr), q(nullptr) {}
431 LogIterator(LogStream& stream, zeroerr::String message = "", zeroerr::String function_name = "",
432 int line = -1);
433 LogIterator(const LogIterator& rhs) : p(rhs.p), q(rhs.q) {}
435 p = rhs.p;
436 q = rhs.q;
437 return *this;
438 }
439
442 LogIterator tmp = *this;
443 ++*this;
444 return tmp;
445 }
446
447 template <typename T>
449 void* data = q->getRawLog(name);
450 if (data) return *(T*)(data);
451 return T{};
452 }
453
454 bool operator==(const LogIterator& rhs) const { return p == rhs.p && q == rhs.q; }
455 bool operator!=(const LogIterator& rhs) const { return !(*this == rhs); }
456
457 LogMessage& get() const { return *q; }
458 LogMessage& operator*() const { return *q; }
459 LogMessage* operator->() const { return q; }
460
461 void check_at_safe_pos();
462
463 friend class LogStream;
464
465protected:
466 bool check_filter();
467 void next();
468
471
474 int line_filter = -1;
475};
476
486public:
487 LogStream();
488 virtual ~LogStream();
489
491 enum LogMode { ASYNC, SYNC };
498
499
521 template <typename... T>
522 PushResult push(T&&... args) {
523 // unsigned size = sizeof(LogMessageImpl<T...>);
524 unsigned size = sizeof(LogMessageImpl<detail::to_store_type_t<T>...>);
525 void* p;
526 if (use_lock_free)
527 p = alloc_block_lockfree(size);
528 else
529 p = alloc_block(size);
530 LogMessage* msg =
531 new (p) LogMessageImpl<detail::to_store_type_t<T>...>(std::forward<T>(args)...);
532 return {msg, size, *this};
533 }
534
535
547 template <typename T>
548 T getLog(zeroerr::String func, unsigned line, zeroerr::String name) {
549 void* data = getRawLog(func, line, name);
550 if (data) return *(T*)(data);
551 return T{};
552 }
553
565 template <typename T>
567 void* data = getRawLog(func, msg, name);
568 if (data) return *(T*)(data);
569 return T{};
570 }
571
572 LogIterator begin(zeroerr::String message = "", zeroerr::String function_name = "", int line = -1) {
573 return LogIterator(*this, message, function_name, line);
574 }
576 LogIterator current(zeroerr::String message = "", zeroerr::String function_name = "", int line = -1);
577
578 void flush();
580 DirMode mode3 = SINGLE_FILE);
581 void setStdoutLogger();
582 void setStderrLogger();
583
584 static LogStream& getDefault();
585
586 void setFlushAtOnce() { flush_mode = FLUSH_AT_ONCE; }
587 void setFlushWhenFull() { flush_mode = FLUSH_WHEN_FULL; }
588 void setFlushManually() { flush_mode = FLUSH_MANUALLY; }
589 void setAsyncLog() { log_mode = ASYNC; }
590 void setSyncLog() { log_mode = SYNC; }
591
592 FlushMode getFlushMode() const { return flush_mode; }
593 void setFlushMode(FlushMode mode) { flush_mode = mode; }
594 LogMode getLogMode() const { return log_mode; }
595 void setLogMode(LogMode mode) { log_mode = mode; }
596
597 bool use_lock_free = true;
598
599 friend class LogIterator;
600
601private:
602 DataBlock *first, *prepare;
603 ZEROERR_ATOMIC(DataBlock*) m_last;
604 Logger* logger = nullptr;
605 FlushMode flush_mode = FLUSH_AT_ONCE;
606 LogMode log_mode = SYNC;
607#ifndef ZEROERR_NO_THREAD_SAFE
608 detail::Mutex* mutex;
609#endif
610
611 // The implementation of alloc objects by giving a size
612 void* alloc_block(unsigned size);
613 void* alloc_block_lockfree(unsigned size);
614
615 // The implementation of getLog which returns a raw pointer
616 // This way can reduce the overhead of code generation by template
617 void* getRawLog(zeroerr::String func, unsigned line, zeroerr::String name);
618 void* getRawLog(zeroerr::String func, zeroerr::String msg, zeroerr::String name);
619};
620
621
622template <typename... T>
623PushResult log(T&&... args) {
624 return LogStream::getDefault().push(std::forward<T>(args)...);
625}
626
627template <typename... T>
628PushResult log(LogStream& stream, T&&... args) {
629 return stream.push(std::forward<T>(args)...);
630}
631
632
639public:
644 virtual void str(zeroerr::StringBuffer& os) const = 0;
645};
646
647extern thread_local std::vector<IContextScope*> _ZEROERR_G_CONTEXT_SCOPE_VECTOR;
648
655template <typename F>
657public:
658 ContextScope(F f) : f_(f) { _ZEROERR_G_CONTEXT_SCOPE_VECTOR.push_back(this); }
660
661 virtual void str(zeroerr::StringBuffer& os) const override { return f_(os); }
662
663protected:
664 F f_;
665};
666
673template <typename F>
675 return ContextScope<F>(f);
676}
677
678
679} // namespace zeroerr
680
682
683#pragma pop_macro("_LIBCPP_REMOVE_TRANSITIVE_INCLUDES")
Template implementation of context scope
Definition log.h:656
ContextScope(F f)
Definition log.h:658
virtual void str(zeroerr::StringBuffer &os) const override
Output context information to a stream
Definition log.h:661
F f_
Definition log.h:664
~ContextScope()
Definition log.h:659
ContextScope is a helper class created in each basic block where you use INFO(). The context scope ca...
Definition log.h:638
virtual void str(zeroerr::StringBuffer &os) const =0
Output context information to a stream
LogIterator is a class to iterate the log messages.
Definition log.h:428
void check_at_safe_pos()
Definition log.cpp:193
DataBlock * p
Definition log.h:469
LogIterator & operator++()
Definition log.cpp:213
int line_filter
Definition log.h:474
LogIterator(const LogIterator &rhs)
Definition log.h:433
LogIterator operator++(int)
Definition log.h:441
LogMessage & operator*() const
Definition log.h:458
LogIterator()
Definition log.h:430
zeroerr::String message_filter
Definition log.h:473
LogMessage & get() const
Definition log.h:457
bool operator!=(const LogIterator &rhs) const
Definition log.h:455
LogMessage * q
Definition log.h:470
bool operator==(const LogIterator &rhs) const
Definition log.h:454
bool check_filter()
Definition log.cpp:220
LogIterator & operator=(const LogIterator &rhs)
Definition log.h:434
T get(zeroerr::String name)
Definition log.h:448
zeroerr::String function_name_filter
Definition log.h:472
void next()
Definition log.cpp:200
LogMessage * operator->() const
Definition log.h:459
LogStream is a class to manage the log messages.
Definition log.h:485
void setFlushMode(FlushMode mode)
Definition log.h:593
void setFlushManually()
Definition log.h:588
LogIterator current(zeroerr::String message="", zeroerr::String function_name="", int line=-1)
Definition log.cpp:138
void setLogMode(LogMode mode)
Definition log.h:595
void setFlushWhenFull()
Definition log.h:587
LogMode
Definition log.h:491
@ SYNC
Definition log.h:491
@ ASYNC
Definition log.h:491
virtual ~LogStream()
Definition log.cpp:78
void flush()
Definition log.cpp:146
void setAsyncLog()
Definition log.h:589
LogStream()
Definition log.cpp:69
FlushMode
Definition log.h:490
@ FLUSH_AT_ONCE
Definition log.h:490
@ FLUSH_MANUALLY
Definition log.h:490
@ FLUSH_WHEN_FULL
Definition log.h:490
T getLog(zeroerr::String func, zeroerr::String msg, zeroerr::String name)
get a log message from the stream
Definition log.h:566
LogIterator begin(zeroerr::String message="", zeroerr::String function_name="", int line=-1)
Definition log.h:572
void setSyncLog()
Definition log.h:590
void setFileLogger(zeroerr::String name, DirMode mode1=SINGLE_FILE, DirMode mode2=SINGLE_FILE, DirMode mode3=SINGLE_FILE)
Definition log.cpp:410
LogMode getLogMode() const
Definition log.h:594
PushResult push(T &&... args)
push a log message to the stream
Definition log.h:522
bool use_lock_free
Definition log.h:597
DirMode
Definition log.h:492
@ SPLIT_BY_SEVERITY
Definition log.h:495
@ SPLIT_BY_CATEGORY
Definition log.h:496
@ DAILY_FILE
Definition log.h:494
@ SINGLE_FILE
Definition log.h:493
void setStderrLogger()
Definition log.cpp:427
void setFlushAtOnce()
Definition log.h:586
FlushMode getFlushMode() const
Definition log.h:592
T getLog(zeroerr::String func, unsigned line, zeroerr::String name)
get a log message from the stream
Definition log.h:548
void setStdoutLogger()
Definition log.cpp:422
friend class LogIterator
Definition log.h:599
LogIterator end()
Definition log.h:575
static LogStream & getDefault()
Definition log.cpp:405
Definition log.h:398
virtual void flush(DataBlock *)=0
virtual ~Logger()=default
Definition buffer.h:7
Definition string.h:41
Definition threadsafe.h:36
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition config.h:283
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition config.h:235
ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH const char * ZEROERR_LOG_CATEGORY
Definition log.cpp:19
STL namespace
typename to_store_type< T >::type to_store_type_t
Definition typetraits.h:285
void visit_at(T &tup, size_t idx, F &&fun)
Definition typetraits.h:306
zeroerr::String gen_str(const char *msg, const T &args, seq< I... >)
Definition log.h:221
Definition assert_text.cpp:5
void suspendLog()
suspend the log to flush to the file
Definition log.cpp:460
thread_local std::vector< IContextScope * > _ZEROERR_G_CONTEXT_SCOPE_VECTOR
Definition log.cpp:26
void setLogCustomCallback(LogCustomCallback callback)
set the log custom callback, this can support custom format of the log message
Definition log.cpp:30
zeroerr::String(* LogCustomCallback)(const LogMessage &, bool colorful)
Definition log.h:281
LogSeverity
Definition log.h:233
@ FATAL_l
Definition log.h:238
@ WARN_l
Definition log.h:236
@ LOG_l
Definition log.h:235
@ INFO_l
Definition log.h:234
@ ERROR_l
Definition log.h:237
PushResult log(T &&... args)
Definition log.h:623
void resumeLog()
resume the log to flush to the file
Definition log.cpp:465
void setLogLevel(LogSeverity level)
set the log level
Definition log.cpp:439
ContextScope< F > MakeContextScope(const F &f)
Helper function to create a context scope
Definition log.h:674
ZEROERR_DIAGNOSTIC_NOINLINE zeroerr::String format(const char *fmt, T &&... args)
Format a string with arguments
Definition format.h:27
void setLogCategory(const char *categories)
set the log category
Definition log.cpp:441
int _ZEROERR_G_VERBOSE
Definition log.cpp:24
Definition log.cpp:58
LogInfo is a struct to store the meta data of the log message.
Definition log.h:266
LogSeverity severity
Definition log.h:273
const char * category
Definition log.h:270
const char * filename
Definition log.h:267
unsigned line
Definition log.h:271
unsigned size
Definition log.h:272
std::map< zeroerr::String, int > names
Definition log.h:274
const char * function
Definition log.h:268
const char * message
Definition log.h:269
void * ptr
Definition log.h:356
void operator()(H &v)
Definition log.h:358
zeroerr::String name
Definition log.h:372
Printer print
Definition log.h:371
std::map< zeroerr::String, zeroerr::String > data
Definition log.h:370
void operator()(H &v)
Definition log.h:380
LogMessageImpl is the implementation of the LogMessage.
Definition log.h:346
void * getRawLog(zeroerr::String name) const override
Definition log.h:363
LogMessageImpl(T... args)
Definition log.h:348
std::tuple< T... > args
Definition log.h:347
zeroerr::String str() const override
Definition log.h:350
std::map< zeroerr::String, zeroerr::String > getData() const override
Definition log.h:385
LogMessage is a class to store the log message.
Definition log.h:316
virtual std::map< zeroerr::String, zeroerr::String > getData() const =0
virtual zeroerr::String str() const =0
virtual void * getRawLog(zeroerr::String name) const =0
Timestamp time
Definition log.h:335
const LogInfo * info
Definition log.h:332
LogMessage()
Definition log.cpp:503
A functor class Printer for printing a value of any type.
Definition print.h:74
bool isCompact
Definition print.h:117
const char * line_break
Definition print.h:120
Definition log.h:404
LogStream & stream
Definition log.h:407
LogMessage * log
Definition log.h:405
unsigned size
Definition log.h:406
Definition time.h:15
Definition typetraits.h:77
Definition typetraits.h:74
#define ZEROERR_ATOMIC(x)
Definition threadsafe.h:31