Skip to content

Commit 6c51f95

Browse files
committed
🔥 Remove logging::level_constant
1 parent 7371d3b commit 6c51f95

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

include/log/fmt/logger.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
#include <stdx/ct_format.hpp>
77
#include <stdx/tuple.hpp>
88
#include <stdx/tuple_algorithms.hpp>
9+
#include <stdx/utility.hpp>
910

1011
#include <fmt/format.h>
1112

1213
#include <chrono>
14+
#include <type_traits>
1315
#include <utility>
1416

15-
template <auto L> struct fmt::formatter<logging::level_constant<L>> {
17+
template <logging::level L>
18+
struct fmt::formatter<std::integral_constant<logging::level, L>> {
1619
constexpr static auto parse(format_parse_context &ctx) {
1720
return ctx.begin();
1821
}
1922

2023
template <typename FormatContext>
21-
auto format(logging::level_constant<L>, FormatContext &ctx) const {
24+
auto format(std::integral_constant<logging::level, L>,
25+
FormatContext &ctx) const {
2226
return ::fmt::format_to(ctx.out(), logging::to_text<L>());
2327
}
2428
};
@@ -38,7 +42,7 @@ template <typename TDestinations> struct log_handler {
3842
stdx::for_each(
3943
[&](auto &out) {
4044
::fmt::format_to(out, "{:>8}us {} [{}]: ", currentTime,
41-
level_constant<L>{}, get_module(Env{}).value);
45+
stdx::ct<L>(), get_module(Env{}).value);
4246
msg.apply(
4347
[&]<typename StringType>(StringType, auto const &...args) {
4448
::fmt::format_to(out, StringType::value, args...);

include/log/level.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ template <level L>
2929
"INFO"sv, "USER1"sv, "USER2"sv, "TRACE"sv};
3030
return level_text[stdx::to_underlying(L)];
3131
}
32-
33-
template <level L> struct level_constant : std::integral_constant<level, L> {};
3432
} // namespace logging

test/log/fmt_logger.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <log/fmt/logger.hpp>
22

33
#include <stdx/ct_string.hpp>
4+
#include <stdx/utility.hpp>
45

56
#include <catch2/catch_test_macros.hpp>
67

@@ -61,49 +62,49 @@ TEST_CASE("log levels are properly represented", "[fmt_logger]") {
6162
{
6263
std::string level{};
6364
fmt::format_to(std::back_inserter(level), "{}",
64-
logging::level_constant<logging::level::TRACE>{});
65+
stdx::ct<logging::level::TRACE>());
6566
CHECK(level == "TRACE");
6667
}
6768
{
6869
std::string level{};
6970
fmt::format_to(std::back_inserter(level), "{}",
70-
logging::level_constant<logging::level::INFO>{});
71+
stdx::ct<logging::level::INFO>());
7172
CHECK(level == "INFO");
7273
}
7374
{
7475
std::string level{};
7576
fmt::format_to(std::back_inserter(level), "{}",
76-
logging::level_constant<logging::level::WARN>{});
77+
stdx::ct<logging::level::WARN>());
7778
CHECK(level == "WARN");
7879
}
7980
{
8081
std::string level{};
8182
fmt::format_to(std::back_inserter(level), "{}",
82-
logging::level_constant<logging::level::ERROR>{});
83+
stdx::ct<logging::level::ERROR>());
8384
CHECK(level == "ERROR");
8485
}
8586
{
8687
std::string level{};
8788
fmt::format_to(std::back_inserter(level), "{}",
88-
logging::level_constant<logging::level::FATAL>{});
89+
stdx::ct<logging::level::FATAL>());
8990
CHECK(level == "FATAL");
9091
}
9192
{
9293
std::string level{};
9394
fmt::format_to(std::back_inserter(level), "{}",
94-
logging::level_constant<logging::level::MAX>{});
95+
stdx::ct<logging::level::MAX>());
9596
CHECK(level == "MAX");
9697
}
9798
{
9899
std::string level{};
99100
fmt::format_to(std::back_inserter(level), "{}",
100-
logging::level_constant<logging::level::USER1>{});
101+
stdx::ct<logging::level::USER1>());
101102
CHECK(level == "USER1");
102103
}
103104
{
104105
std::string level{};
105106
fmt::format_to(std::back_inserter(level), "{}",
106-
logging::level_constant<logging::level::USER2>{});
107+
stdx::ct<logging::level::USER2>());
107108
CHECK(level == "USER2");
108109
}
109110
}

0 commit comments

Comments
 (0)