This repository was archived by the owner on Apr 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacros.h
More file actions
43 lines (34 loc) · 1.73 KB
/
macros.h
File metadata and controls
43 lines (34 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
constexpr cpplog::LogLevel LVL_TRACE = cpplog::LogLevel::Trace;
constexpr cpplog::LogLevel LVL_DEBUG = cpplog::LogLevel::Debug;
constexpr cpplog::LogLevel LVL_INFO = cpplog::LogLevel::Information;
constexpr cpplog::LogLevel LVL_WARNING = cpplog::LogLevel::Warning;
constexpr cpplog::LogLevel LVL_ERROR = cpplog::LogLevel::Error;
constexpr cpplog::LogLevel LVL_FATAL = cpplog::LogLevel::Fatal;
#ifdef __GNUC__
#define __FUNCTION_SIGNATURE__ __PRETTY_FUNCTION__
#elif defined(_MSC_VER)
#define __FUNCTION_SIGNATURE__ __FUNCSIG__
#else
#define __FUNCTION_SIGNATURE__ ""
#endif
#define SOURCE_LOCATION cpplog::source_location{__FILE__, __func__, __LINE__}
#define LOG_TO_IMPL(sink, level, fmt, ...) \
if (sink.is_level_enabled(level)) \
cpplog::LogCapture(sink, level, SOURCE_LOCATION) \
.message(fmt, ##__VA_ARGS__)
#define LOG_TO(sink, level, fmt, ...) \
LOG_TO_IMPL(sink, LVL_##level, fmt, ##__VA_ARGS__)
#define LOG(level, fmt, ...) \
LOG_TO_IMPL(cpplog::LogDispatcher::instance(), LVL_##level, fmt, ##__VA_ARGS__)
#define LOG_TO_IF(sink, level, condition, fmt, ...) \
if (condition) LOG_TO_IMPL(sink, LVL_##level, fmt, ##__VA_ARGS__)
#define LOG_IF(level, condition, fmt, ...) \
if (condition) LOG_TO_IMPL(cpplog::LogDispatcher::instance(), \
LVL_##level, fmt, ##__VA_ARGS__)
#define LOG_EVERY_N(level, n, fmt, ...) \
static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
++LOG_OCCURRENCES; \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
LOG_TO_IMPL(cpplog::LogDispatcher::instance(), LVL_##level, fmt, ##__VA_ARGS__)