6#pragma push_macro("_LIBCPP_REMOVE_TRANSITIVE_INCLUDES")
7#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
8#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
35#define ZEROERR_INFO(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_INFO_(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
36#define ZEROERR_LOG(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(LOG_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
37#define ZEROERR_WARN(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(WARN_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
38#define ZEROERR_ERROR(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(ERROR_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
39#define ZEROERR_FATAL(...) ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(FATAL_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
42#ifdef ZEROERR_USE_SHORT_LOG_MACRO
68#define INFO(...) ZEROERR_INFO(__VA_ARGS__)
69#define LOG(...) ZEROERR_LOG(__VA_ARGS__)
70#define WARN(...) ZEROERR_WARN(__VA_ARGS__)
71#define ERR(...) ZEROERR_ERROR(__VA_ARGS__)
72#define FATAL(...) ZEROERR_FATAL(__VA_ARGS__)
73#define VERBOSE(v) ZEROERR_VERBOSE(v)
75#define LOG_GET(func, id, name, type) ZEROERR_LOG_GET(func, id, name, type)
79#define ZEROERR_LOG_IF(condition, ACTION, ...) \
81 if (condition) ACTION(__VA_ARGS__); \
85#define INFO_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_INFO, __VA_ARGS__)
86#define LOG_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_LOG, __VA_ARGS__)
87#define WARN_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_WARN, __VA_ARGS__)
88#define ERR_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_ERROR, __VA_ARGS__)
89#define FATAL_IF(cond, ...) ZEROERR_LOG_IF(cond, ZEROERR_FATAL, __VA_ARGS__)
92#define ZEROERR_LOG_EVERY_(n, ACTION, ...) \
94 static unsigned counter = 0; \
97 ACTION(__VA_ARGS__); \
103#define INFO_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_INFO, __VA_ARGS__)
104#define LOG_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_LOG, __VA_ARGS__)
105#define WARN_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_WARN, __VA_ARGS__)
106#define ERR_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_ERROR, __VA_ARGS__)
107#define FATAL_EVERY_(n, ...) ZEROERR_LOG_EVERY_(n, ZEROERR_FATAL, __VA_ARGS__)
110#define ZEROERR_LOG_IF_EVERY_(n, cond, ACTION, ...) \
113 static unsigned counter = 0; \
114 if (counter == 0) { \
116 ACTION(__VA_ARGS__); \
122#define INFO_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_INFO, __VA_ARGS__)
123#define LOG_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_LOG, __VA_ARGS__)
124#define WARN_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_WARN, __VA_ARGS__)
125#define ERR_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
126#define FATAL_IF_EVERY_(n, cond, ...) ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_FATAL, __VA_ARGS__)
128#define ZEROERR_LOG_FIRST(cond, ACTION, ...) \
130 static bool first = true; \
131 if (first && (cond)) { \
133 ACTION(__VA_ARGS__); \
137#define INFO_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_INFO, __VA_ARGS__)
138#define LOG_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_LOG, __VA_ARGS__)
139#define WARN_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_WARN, __VA_ARGS__)
140#define ERR_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_ERROR, __VA_ARGS__)
141#define FATAL_FIRST(cond, ...) ZEROERR_LOG_FIRST(cond, ZEROERR_FATAL, __VA_ARGS__)
143#define ZEROERR_LOG_FIRST_(n, cond, ACTION, ...) \
145 static unsigned counter = n; \
146 if (counter && (cond)) { \
148 ACTION(__VA_ARGS__); \
152#define INFO_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_INFO, __VA_ARGS__)
153#define LOG_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_LOG, __VA_ARGS__)
154#define WARN_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_WARN, __VA_ARGS__)
155#define ERR_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
156#define FATAL_FIRST_(n, cond, ...) ZEROERR_LOG_FIRST_(n, cond, ZEROERR_FATAL, __VA_ARGS__)
159#define DLOG(ACTION, ...) ZEROERR_EXPAND(ACTION(__VA_ARGS__))
161#define DLOG(ACTION, ...)
166#define ZEROERR_VERBOSE(v) if (zeroerr::_ZEROERR_G_VERBOSE >= (v))
168#define ZEROERR_LOG_(severity, message, ...) \
170 ZEROERR_G_CONTEXT_SCOPE(true); \
171 auto msg = zeroerr::makeLogRecord(__VA_ARGS__); \
173 static zeroerr::LogInfo log_info{__FILE__, \
176 ZEROERR_LOG_CATEGORY, \
179 zeroerr::LogSeverity::severity}; \
180 msg.entry.info = &log_info; \
181 msg.stream.write(std::move(msg.entry)); \
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;
347template <
typename... T>
359 template <
typename H>
372 std::map<zeroerr::String, zeroerr::String>
data;
377 print.isCompact =
true;
378 print.line_break =
"";
381 template <
typename H>
387 std::map<zeroerr::String, zeroerr::String>
getData()
const override {
389 for (
auto it =
info->names.begin(); it !=
info->names.end(); ++it) {
390 printer.
name = it->first;
449 template <
typename T>
451 void* data =
q->getRawLog(name);
452 if (data)
return *(T*)(data);
525 template <
typename... T>
528 "Over-aligned log arguments are not supported");
531 void* p = alloc_block(size);
535 return {msg, size, *
this};
541 template <
typename... T>
543 static_assert(
alignof(
LogMessageImpl<T...>) <=
alignof(std::max_align_t),
544 "Over-aligned log arguments are not supported");
546 void* storage = alloc_block(
sizeof(message));
549 commit_block(
last,
sizeof(message));
564 template <
typename T>
566 void* data = getRawLog(func, line, name);
567 if (data)
return *(T*)(data);
582 template <
typename T>
584 void* data = getRawLog(func, msg, name);
585 if (data)
return *(T*)(data);
590 return LogIterator(*
this, message, function_name, line);
625#ifndef ZEROERR_NO_THREAD_SAFE
630 void* alloc_block(
unsigned size);
631 void commit_block(
DataBlock* block,
unsigned size);
632 void flush_unlocked();
643template <
typename... T>
651template <
typename... T>
653 return LogRecord<T...>(stream, std::forward<T>(args)...);
656template <
typename... T>
661template <
typename... T>
666template <
typename... T>
668 return stream.
push(std::forward<T>(args)...);
722#pragma pop_macro("_LIBCPP_REMOVE_TRANSITIVE_INCLUDES")
Template implementation of context scope.
Definition log.h:695
ContextScope(F f)
Definition log.h:697
virtual void str(zeroerr::StringBuffer &os) const override
Output context information to a stream.
Definition log.h:700
~ContextScope()
Definition log.h:698
ContextScope is a helper class created in each basic block where you use INFO(). The context scope ca...
Definition log.h:677
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:430
void check_at_safe_pos()
Definition log.cpp:186
DataBlock * p
Definition log.h:471
LogIterator & operator++()
Definition log.cpp:206
int line_filter
Definition log.h:476
LogIterator(const LogIterator &rhs)
Definition log.h:435
LogIterator operator++(int)
Definition log.h:443
LogMessage & operator*() const
Definition log.h:460
LogIterator()
Definition log.h:432
zeroerr::String message_filter
Definition log.h:475
LogMessage & get() const
Definition log.h:459
bool operator!=(const LogIterator &rhs) const
Definition log.h:457
LogMessage * q
Definition log.h:472
bool operator==(const LogIterator &rhs) const
Definition log.h:456
friend class LogStream
Definition log.h:465
bool check_filter()
Definition log.cpp:213
LogIterator & operator=(const LogIterator &rhs)
Definition log.h:436
T get(zeroerr::String name)
Definition log.h:450
zeroerr::String function_name_filter
Definition log.h:474
void next()
Definition log.cpp:193
LogMessage * operator->() const
Definition log.h:461
LogStream is a class to manage the log messages.
Definition log.h:487
void setFlushMode(FlushMode mode)
Definition log.h:610
void setFlushManually()
Definition log.h:605
LogIterator current(zeroerr::String message="", zeroerr::String function_name="", int line=-1)
Definition log.cpp:125
void write(LogMessageImpl< T... > &&message)
Definition log.h:542
void setLogMode(LogMode mode)
Definition log.h:612
void setFlushWhenFull()
Definition log.h:604
LogMode
Definition log.h:493
@ SYNC
Definition log.h:493
@ ASYNC
Definition log.h:493
virtual ~LogStream()
Definition log.cpp:89
void flush()
Definition log.cpp:133
void setAsyncLog()
Definition log.h:606
LogStream()
Definition log.cpp:81
FlushMode
Definition log.h:492
@ FLUSH_AT_ONCE
Definition log.h:492
@ FLUSH_MANUALLY
Definition log.h:492
@ FLUSH_WHEN_FULL
Definition log.h:492
T getLog(zeroerr::String func, zeroerr::String msg, zeroerr::String name)
get a log message from the stream
Definition log.h:583
LogIterator begin(zeroerr::String message="", zeroerr::String function_name="", int line=-1)
Definition log.h:589
void setSyncLog()
Definition log.h:607
void setFileLogger(zeroerr::String name, DirMode mode1=SINGLE_FILE, DirMode mode2=SINGLE_FILE, DirMode mode3=SINGLE_FILE)
Definition log.cpp:404
LogMode getLogMode() const
Definition log.h:611
PushResult push(T &&... args)
push a log message to the stream
Definition log.h:526
bool use_lock_free
Definition log.h:615
DirMode
Definition log.h:494
@ SPLIT_BY_SEVERITY
Definition log.h:497
@ SPLIT_BY_CATEGORY
Definition log.h:498
@ DAILY_FILE
Definition log.h:496
@ SINGLE_FILE
Definition log.h:495
void setStderrLogger()
Definition log.cpp:421
void setFlushAtOnce()
Definition log.h:603
FlushMode getFlushMode() const
Definition log.h:609
T getLog(zeroerr::String func, unsigned line, zeroerr::String name)
get a log message from the stream
Definition log.h:565
void setStdoutLogger()
Definition log.cpp:416
friend class LogIterator
Definition log.h:617
LogIterator end()
Definition log.h:592
static LogStream & getDefault()
Definition log.cpp:399
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
const char * ZEROERR_LOG_CATEGORY
Definition log.cpp:20
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
typename to_store_type< T >::type to_store_type_t
Definition typetraits.h:285
Definition assert_text.cpp:5
void suspendLog()
suspend the log to flush to the file
Definition log.cpp:454
std::vector< IContextScope * > _ZEROERR_G_CONTEXT_SCOPE_VECTOR
Definition log.cpp:27
void setLogCustomCallback(LogCustomCallback callback)
set the log custom callback, this can support custom format of the log message
Definition log.cpp:31
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:662
void resumeLog()
resume the log to flush to the file
Definition log.cpp:459
void setLogLevel(LogSeverity level)
set the log level
Definition log.cpp:433
ContextScope< F > MakeContextScope(const F &f)
Helper function to create a context scope.
Definition log.h:713
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:435
int _ZEROERR_G_VERBOSE
Definition log.cpp:25
LogRecord< T... > makeLogRecord(LogStream &stream, T &&... args)
Definition log.h:652
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
LogInfo(const char *filename, const char *function, const char *message, const char *category, unsigned line, unsigned size, LogSeverity severity)
Definition log.cpp:34
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:358
void operator()(H &v)
Definition log.h:360
PrintTupleData()
Definition log.h:376
zeroerr::String name
Definition log.h:374
Printer print
Definition log.h:373
std::map< zeroerr::String, zeroerr::String > data
Definition log.h:372
void operator()(H &v)
Definition log.h:382
LogMessageImpl is the implementation of the LogMessage.
Definition log.h:348
void * getRawLog(zeroerr::String name) const override
Definition log.h:365
LogMessageImpl(T... args)
Definition log.h:350
std::tuple< T... > args
Definition log.h:349
zeroerr::String str() const override
Definition log.h:352
std::map< zeroerr::String, zeroerr::String > getData() const override
Definition log.h:387
LogMessage is a class to store the log message.
Definition log.h:316
virtual std::map< zeroerr::String, zeroerr::String > getData() const =0
virtual ~LogMessage()=default
virtual zeroerr::String str() const =0
virtual void * getRawLog(zeroerr::String name) const =0
Timestamp time
Definition log.h:337
const LogInfo * info
Definition log.h:332
LogMessage()
Definition log.cpp:497
LogStream & stream
Definition log.h:645
LogMessageImpl< detail::to_store_type_t< T >... > entry
Definition log.h:646
LogRecord(LogStream &stream, T &&... args)
Definition log.h:647
A functor class Printer for printing a value of any type.
Definition print.h:87
LogStream & stream
Definition log.h:409
LogMessage * log
Definition log.h:407
unsigned size
Definition log.h:408
Definition typetraits.h:77
Definition typetraits.h:74
#define ZEROERR_LOAD(x)
Definition threadsafe.h:32
#define ZEROERR_ATOMIC(x)
Definition threadsafe.h:31
#define ZEROERR_LOCK(x)
Definition threadsafe.h:30