|
4 | 4 | #include <log/flavor.hpp>
|
5 | 5 | #include <log/level.hpp>
|
6 | 6 | #include <log/module.hpp>
|
| 7 | +#include <log/pp_map.hpp> |
7 | 8 |
|
8 | 9 | #include <stdx/compiler.hpp>
|
9 | 10 | #include <stdx/ct_format.hpp>
|
@@ -55,18 +56,42 @@ static auto log(TArgs &&...args) -> void {
|
55 | 56 | auto &cfg = get_config<Env, Ts...>();
|
56 | 57 | cfg.logger.template log<Env>(std::forward<TArgs>(args)...);
|
57 | 58 | }
|
| 59 | + |
| 60 | +namespace detail { |
| 61 | +template <typename F> constexpr auto cx_wrap(F f) { |
| 62 | + // NOLINTBEGIN(bugprone-branch-clone) |
| 63 | + if constexpr (requires { stdx::ct<decltype(f())::value>(); }) { |
| 64 | + return f(); |
| 65 | + } else if constexpr (requires { stdx::ct<f()>(); }) { |
| 66 | + return stdx::ct<f()>(); |
| 67 | + } else { |
| 68 | + return f(); |
| 69 | + } |
| 70 | + // NOLINTEND(bugprone-branch-clone) |
| 71 | +} |
| 72 | + |
| 73 | +template <stdx::ct_string Msg> constexpr auto cx_log_wrap(int, auto &&...args) { |
| 74 | + return stdx::ct_format<Msg>(FWD(args)...); |
| 75 | +} |
| 76 | +} // namespace detail |
58 | 77 | } // namespace logging
|
59 | 78 |
|
60 | 79 | // NOLINTBEGIN(cppcoreguidelines-macro-usage)
|
61 | 80 |
|
| 81 | +#define CIB_CX_WRAP(...) \ |
| 82 | + __VA_OPT__(, logging::detail::cx_wrap([&] { return __VA_ARGS__; })) |
| 83 | + |
62 | 84 | #define CIB_LOG(MSG, ...) \
|
63 | 85 | logging::log<cib_log_env_t>(__FILE__, __LINE__, \
|
64 |
| - stdx::ct_format<MSG>(__VA_ARGS__)) |
| 86 | + logging::detail::cx_log_wrap<MSG>( \ |
| 87 | + 0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__))) |
65 | 88 |
|
66 | 89 | #define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \
|
67 | 90 | logging::log< \
|
68 | 91 | stdx::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
|
69 |
| - __FILE__, __LINE__, stdx::ct_format<MSG>(__VA_ARGS__)) |
| 92 | + __FILE__, __LINE__, \ |
| 93 | + logging::detail::cx_log_wrap<MSG>( \ |
| 94 | + 0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__))) |
70 | 95 |
|
71 | 96 | #define CIB_TRACE(...) \
|
72 | 97 | CIB_LOG_WITH_LEVEL(logging::level::TRACE __VA_OPT__(, ) __VA_ARGS__)
|
@@ -127,7 +152,7 @@ template <stdx::ct_string Fmt, typename Env, typename F, typename L>
|
127 | 152 |
|
128 | 153 | #define CIB_FATAL(MSG, ...) \
|
129 | 154 | logging::detail::panic<MSG, cib_log_env_t>( \
|
130 |
| - __FILE__, __LINE__ __VA_OPT__(, ) __VA_ARGS__) |
| 155 | + __FILE__, __LINE__ CIB_MAP(CIB_CX_WRAP, __VA_ARGS__)) |
131 | 156 |
|
132 | 157 | #define CIB_ASSERT(expr, ...) \
|
133 | 158 | ((expr) \
|
|
0 commit comments