diff --git a/include/log/log.hpp b/include/log/log.hpp index c387e77f..fecdea7d 100644 --- a/include/log/log.hpp +++ b/include/log/log.hpp @@ -91,7 +91,7 @@ template constexpr auto cx_log_wrap(int, auto &&...args) { #define CIB_ERROR(...) \ CIB_LOG_WITH_LEVEL(logging::level::ERROR __VA_OPT__(, ) __VA_ARGS__) -namespace logging::detail { +namespace logging { template [[nodiscard]] constexpr auto panic(F file, L line, auto &&...args) { STDX_PRAGMA(diagnostic push) @@ -102,14 +102,12 @@ template constexpr auto N = stdx::num_fmt_specifiers; constexpr auto sz = sizeof...(args); - using env_t = - stdx::extend_env_t; #if __cpp_pack_indexing >= 202311L auto s = [&](std::index_sequence) { return stdx::ct_format(FWD(args...[Is])...); }(std::make_index_sequence{}); - logging::log(file, line, s); + log(file, line, s); [&](std::index_sequence) { stdx::panic(std::move(s).args, @@ -127,7 +125,7 @@ template auto s = stdx::get<0>(std::move(t)).apply([](auto &&...fmt_args) { return stdx::ct_format(FWD(fmt_args)...); }); - logging::log(file, line, s); + log(file, line, s); stdx::get<1>(std::move(t)).apply([&](auto &&...extra_args) { stdx::panic(std::move(s).args, @@ -137,10 +135,11 @@ template STDX_PRAGMA(diagnostic pop) } -} // namespace logging::detail +} // namespace logging #define CIB_FATAL(MSG, ...) \ - logging::detail::panic( \ + logging::panic>( \ __FILE__, __LINE__ __VA_OPT__(, STDX_MAP(CX_WRAP, __VA_ARGS__))) #define CIB_ASSERT(expr, ...) \ diff --git a/test/log/log.cpp b/test/log/log.cpp index 7fc4fe07..2c46df49 100644 --- a/test/log/log.cpp +++ b/test/log/log.cpp @@ -161,3 +161,28 @@ TEST_CASE("CIB_ASSERT passes arguments to panic", "[log]") { CHECK(buffer.find(expected_why) != std::string::npos); CHECK(panicked); } + +namespace { +enum struct custom_level { THE_ONE_LEVEL = 5 }; +} + +namespace logging { +template +[[nodiscard]] auto format_as(level_wrapper) -> std::string_view { + STATIC_REQUIRE(L == custom_level::THE_ONE_LEVEL); + return "THE_ONE_LEVEL"; +} +} // namespace logging + +#define CUSTOM_FATAL(MSG, ...) \ + logging::panic>( \ + __FILE__, __LINE__ __VA_OPT__(, STDX_MAP(CX_WRAP, __VA_ARGS__))) + +TEST_CASE("panic works with custom level", "[log]") { + reset_test_state(); + + CUSTOM_FATAL("Hello"); + CAPTURE(buffer); + CHECK(buffer.find("THE_ONE_LEVEL") != std::string::npos); +}