|
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,50 @@ 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> constexpr auto is_already_ct = false; |
| 62 | +template <typename T, T V> |
| 63 | +constexpr auto is_already_ct<std::integral_constant<T, V>> = true; |
| 64 | +template <stdx::ct_string S> |
| 65 | +constexpr auto is_already_ct<stdx::cts_t<S>> = true; |
| 66 | +template <typename T> |
| 67 | +constexpr auto is_already_ct<stdx::type_identity<T>> = true; |
| 68 | + |
| 69 | +template <stdx::ct_string Msg> constexpr auto cx_log_wrap(int, auto &&...args) { |
| 70 | + return stdx::ct_format<Msg>(FWD(args)...); |
| 71 | +} |
| 72 | +} // namespace detail |
58 | 73 | } // namespace logging
|
59 | 74 |
|
60 | 75 | // NOLINTBEGIN(cppcoreguidelines-macro-usage)
|
61 | 76 |
|
| 77 | +#define CIB_CX_WRAP1(X) \ |
| 78 | + [&](auto f) { \ |
| 79 | + if constexpr (::logging::detail::is_already_ct<decltype(f())>) { \ |
| 80 | + return f(); \ |
| 81 | + } else if constexpr (requires { \ |
| 82 | + stdx::ct<[&]() constexpr { return X; }()>; \ |
| 83 | + }) { \ |
| 84 | + return stdx::ct<f()>(); \ |
| 85 | + } else { \ |
| 86 | + return f(); \ |
| 87 | + } \ |
| 88 | + }([&] { return X; }) |
| 89 | + |
| 90 | +#define CIB_CX_WRAP(...) __VA_OPT__(, CIB_CX_WRAP1(__VA_ARGS__)) |
| 91 | + |
62 | 92 | #define CIB_LOG(MSG, ...) \
|
63 | 93 | logging::log<cib_log_env_t>(__FILE__, __LINE__, \
|
64 |
| - stdx::ct_format<MSG>(__VA_ARGS__)) |
| 94 | + logging::detail::cx_log_wrap<MSG>( \ |
| 95 | + 0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__))) |
65 | 96 |
|
66 | 97 | #define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \
|
67 | 98 | logging::log< \
|
68 | 99 | stdx::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
|
69 |
| - __FILE__, __LINE__, stdx::ct_format<MSG>(__VA_ARGS__)) |
| 100 | + __FILE__, __LINE__, \ |
| 101 | + logging::detail::cx_log_wrap<MSG>( \ |
| 102 | + 0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__))) |
70 | 103 |
|
71 | 104 | #define CIB_TRACE(...) \
|
72 | 105 | CIB_LOG_WITH_LEVEL(logging::level::TRACE __VA_OPT__(, ) __VA_ARGS__)
|
@@ -127,7 +160,7 @@ template <stdx::ct_string Fmt, typename Env, typename F, typename L>
|
127 | 160 |
|
128 | 161 | #define CIB_FATAL(MSG, ...) \
|
129 | 162 | logging::detail::panic<MSG, cib_log_env_t>( \
|
130 |
| - __FILE__, __LINE__ __VA_OPT__(, ) __VA_ARGS__) |
| 163 | + __FILE__, __LINE__ CIB_MAP(CIB_CX_WRAP, __VA_ARGS__)) |
131 | 164 |
|
132 | 165 | #define CIB_ASSERT(expr, ...) \
|
133 | 166 | ((expr) \
|
|
0 commit comments