6#pragma push_macro("_LIBCPP_REMOVE_TRANSITIVE_INCLUDES")
7#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
8#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
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
41#ifdef ZEROERR_USE_SHORT_LOG_MACRO
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)
74#define LOG_GET(func, id, name, type) ZEROERR_LOG_GET(func, id, name, type)
78#define ZEROERR_LOG_IF(condition, ACTION, ...) \
80 if (condition) ACTION(__VA_ARGS__); \
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__)
91#define ZEROERR_LOG_EVERY_(n, ACTION, ...) \
93 static unsigned counter = 0; \
96 ACTION(__VA_ARGS__); \
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__)
109#define ZEROERR_LOG_IF_EVERY_(n, cond, ACTION, ...) \
112 static unsigned counter = 0; \
113 if (counter == 0) { \
115 ACTION(__VA_ARGS__); \
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__)
127#define ZEROERR_LOG_FIRST(cond, ACTION, ...) \
129 static bool first = true; \
130 if (first && (cond)) { \
132 ACTION(__VA_ARGS__); \
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__)
142#define ZEROERR_LOG_FIRST_(n, cond, ACTION, ...) \
144 static unsigned counter = n; \
145 if (counter && (cond)) { \
147 ACTION(__VA_ARGS__); \
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__)
158#define DLOG(ACTION, ...) ZEROERR_EXPAND(ACTION(__VA_ARGS__))
160#define DLOG(ACTION, ...)
165#define ZEROERR_VERBOSE(v) if (zeroerr::_ZEROERR_G_VERBOSE >= (v))
167#define ZEROERR_LOG_(severity, message, ...) \
169 ZEROERR_G_CONTEXT_SCOPE(true); \
170 auto msg = zeroerr::log(__VA_ARGS__); \
172 static zeroerr::LogInfo log_info{__FILE__, \
175 ZEROERR_LOG_CATEGORY, \
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(); \
184#define ZEROERR_INFO_(...) \
185 ZEROERR_INFO_IMPL(ZEROERR_NAMEGEN(_capture_), ZEROERR_NAMEGEN(_capture_), __VA_ARGS__)
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__); \
194#ifdef ZEROERR_G_CONTEXT_SCOPE
195#undef ZEROERR_G_CONTEXT_SCOPE
198#define ZEROERR_G_CONTEXT_SCOPE(x) \
200 for (auto* zeroerr_context_scope : zeroerr::_ZEROERR_G_CONTEXT_SCOPE_VECTOR) { \
201 zeroerr_context_scope->str(zeroerr::getStderrPrinter().os); \
205#ifdef ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER
206#undef ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER
209#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER(cond, level, ...) \
210 ZEROERR_LOG_IF(cond, level, __VA_ARGS__)
214#define ZEROERR_LOG_GET(func, id, name, type) \
215 zeroerr::LogStream::getDefault().getLog<type>(#func, id, #name)
220template <
typename T,
unsigned... I>
222 return format(msg, std::get<I>(args)...);
274 std::map<zeroerr::String, int>
names;
329 virtual std::map<zeroerr::String, zeroerr::String>
getData()
const = 0;
345template <
typename... T>
357 template <
typename H>
370 std::map<zeroerr::String, zeroerr::String>
data;
379 template <
typename H>
385 std::map<zeroerr::String, zeroerr::String>
getData()
const override {
388 printer.
name = it->first;
447 template <
typename T>
450 if (data)
return *(T*)(data);
521 template <
typename... T>
527 p = alloc_block_lockfree(size);
529 p = alloc_block(size);
532 return {msg, size, *
this};
547 template <
typename T>
549 void* data = getRawLog(func, line, name);
550 if (data)
return *(T*)(data);
565 template <
typename T>
567 void* data = getRawLog(func, msg, name);
568 if (data)
return *(T*)(data);
573 return LogIterator(*
this, message, function_name, line);
607#ifndef ZEROERR_NO_THREAD_SAFE
612 void* alloc_block(
unsigned size);
613 void* alloc_block_lockfree(
unsigned size);
622template <
typename... T>
627template <
typename... T>
629 return stream.
push(std::forward<T>(args)...);
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
~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
virtual void flush(DataBlock *)=0
virtual ~Logger()=default
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
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
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
PrintTupleData()
Definition log.h:374
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
LogStream & stream
Definition log.h:407
LogMessage * log
Definition log.h:405
unsigned size
Definition log.h:406
Definition typetraits.h:77
Definition typetraits.h:74
#define ZEROERR_ATOMIC(x)
Definition threadsafe.h:31