44#include < log/log.hpp>
55#include < log/module.hpp>
66
7+ #include < stdx/bit.hpp>
78#include < stdx/ct_format.hpp>
8- #include < stdx/tuple.hpp>
99#include < stdx/tuple_algorithms.hpp>
10- #include < stdx/utility .hpp>
10+ #include < stdx/type_traits .hpp>
1111
1212#include < fmt/format.h>
1313
14+ #include < array>
1415#include < chrono>
15- #include < type_traits>
16+ #include < iterator>
17+ #include < string_view>
1618#include < utility>
1719
20+ namespace logging {
21+ template <auto > struct level_wrapper {};
22+
23+ namespace fmt_detail {
24+ using namespace std ::string_view_literals;
25+ constexpr std::array level_text{" MAX" sv, " FATAL" sv, " ERROR" sv, " WARN" sv,
26+ " INFO" sv, " USER1" sv, " USER2" sv, " TRACE" sv};
27+ } // namespace fmt_detail
28+
1829template <logging::level L>
19- struct fmt ::formatter<std::integral_constant<logging::level, L>> {
20- constexpr static auto parse (format_parse_context &ctx) {
21- return ctx.begin ();
22- }
30+ constexpr std::string_view level_text =
31+ fmt_detail::level_text[stdx::to_underlying(L)];
2332
24- template <typename FormatContext>
25- auto format (std::integral_constant<logging::level, L>,
26- FormatContext &ctx) const {
27- return ::fmt::format_to (ctx.out (), logging::to_text<L>());
28- }
29- };
33+ template <logging::level L>
34+ [[nodiscard]] constexpr auto format_as (level_wrapper<L>) -> std::string_view {
35+ return level_text<L>;
36+ }
3037
31- namespace logging :: fmt {
38+ namespace fmt {
3239template <typename TDestinations> struct log_handler {
3340 constexpr explicit log_handler (TDestinations &&ds) : dests{std::move (ds)} {}
3441
@@ -43,7 +50,8 @@ template <typename TDestinations> struct log_handler {
4350 stdx::for_each (
4451 [&](auto &out) {
4552 ::fmt::format_to (out, " {:>8}us {} [{}]: " , currentTime,
46- get_level (Env{}), get_module(Env{}).value);
53+ level_wrapper<get_level(Env{}).value>{},
54+ get_module (Env{}).value );
4755 msg.apply (
4856 [&]<typename StringType>(StringType, auto const &...args ) {
4957 ::fmt::format_to (out, StringType::value, args...);
@@ -65,4 +73,5 @@ template <typename... TDestinations> struct config {
6573
6674 log_handler<destinations_tuple_t > logger;
6775};
68- } // namespace logging::fmt
76+ } // namespace fmt
77+ } // namespace logging
0 commit comments