diff --git a/include/flow/impl.hpp b/include/flow/impl.hpp index 875ecef1..47733ed4 100644 --- a/include/flow/impl.hpp +++ b/include/flow/impl.hpp @@ -2,9 +2,6 @@ #include #include -#include -#include -#include #include #include @@ -22,13 +19,11 @@ template constexpr auto run_func() -> void { if (CTNode::condition) { if constexpr (not FlowName.empty()) { - using log_spec_t = - decltype(get_log_spec>()); - CIB_LOG_ENV(logging::get_level, log_spec_t::level, - logging::get_flavor, - stdx::type_identity{}); - CIB_LOG("flow.{}({})", typename CTNode::type_t{}, - typename CTNode::name_t{}); + logging::log< + decltype(get_log_env>())>( + __FILE__, __LINE__, + sc::format("flow.{}({})"_sc, typename CTNode::type_t{}, + typename CTNode::name_t{})); } typename CTNode::func_t{}(); } @@ -65,21 +60,15 @@ template struct inlined_func_list { stdx::ct_string_to_type(); if constexpr (loggingEnabled) { - using log_spec_t = decltype(get_log_spec()); - CIB_LOG_ENV(logging::get_level, log_spec_t::level, - logging::get_flavor, - stdx::type_identity{}); - CIB_LOG("flow.start({})", name); + logging::log())>( + __FILE__, __LINE__, sc::format("flow.start({})"_sc, name)); } (FuncPtrs(), ...); if constexpr (loggingEnabled) { - using log_spec_t = decltype(get_log_spec()); - CIB_LOG_ENV(logging::get_level, log_spec_t::level, - logging::get_flavor, - stdx::type_identity{}); - CIB_LOG("flow.end({})", name); + logging::log())>( + __FILE__, __LINE__, sc::format("flow.end({})"_sc, name)); } } }; diff --git a/include/flow/log.hpp b/include/flow/log.hpp index 7ed5a397..d34516ed 100644 --- a/include/flow/log.hpp +++ b/include/flow/log.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -7,30 +8,28 @@ #include namespace flow { -struct default_log_spec { - using flavor = logging::default_flavor_t; - constexpr static auto level = logging::level::TRACE; -}; +using default_log_env = + logging::make_env_t; template -constexpr auto log_spec = default_log_spec{}; +constexpr auto log_env = default_log_env{}; -template struct log_spec_id_t { +template struct log_env_id_t { constexpr static auto ct_name = Name; }; -template , +template , typename... DummyArgs> requires(sizeof...(DummyArgs) == 0) -constexpr static auto get_log_spec() { - using log_spec_t = decltype(log_spec); - if constexpr (std::is_same_v) { +constexpr static auto get_log_env() { + using log_env_t = decltype(log_env); + if constexpr (std::is_same_v) { if constexpr (Fallback::ct_name == stdx::ct_string{"default"}) { - return log_spec; + return log_env; } else { - return get_log_spec(); + return get_log_env(); } } else { - return log_spec_t{}; + return log_env_t{}; } } } // namespace flow diff --git a/test/flow/custom_log_levels.cpp b/test/flow/custom_log_levels.cpp index 88e324ad..9d22e497 100644 --- a/test/flow/custom_log_levels.cpp +++ b/test/flow/custom_log_levels.cpp @@ -50,16 +50,19 @@ struct log_config { template <> inline auto logging::config<> = log_config{}; -struct user1_log_spec : flow::default_log_spec { - constexpr static auto level = logging::level::USER1; -}; -struct user2_log_spec : flow::default_log_spec { - constexpr static auto level = logging::level::USER2; -}; -struct info_log_spec : flow::default_log_spec { - constexpr static auto level = logging::level::INFO; -}; -template <> constexpr auto flow::log_spec<"default"> = info_log_spec{}; +using user1_log_env = + logging::extend_env_t; + +using user2_log_env = + logging::extend_env_t; + +using info_log_env = + logging::extend_env_t; + +template <> constexpr auto flow::log_env<"default"> = info_log_env{}; TEST_CASE("override default log level", "[flow_custom_log_levels]") { run_flow, @@ -70,8 +73,8 @@ TEST_CASE("override default log level", "[flow_custom_log_levels]") { [](auto level) { CHECK(level == logging::level::INFO); }); } -template <> constexpr auto flow::log_spec<"B"> = user1_log_spec{}; -template <> constexpr auto flow::log_spec<"msB"> = user2_log_spec{}; +template <> constexpr auto flow::log_env<"B"> = user1_log_env{}; +template <> constexpr auto flow::log_env<"msB"> = user2_log_env{}; TEST_CASE("override log level by name", "[flow_custom_log_levels]") { run_flow, @@ -83,7 +86,7 @@ TEST_CASE("override log level by name", "[flow_custom_log_levels]") { CHECK(log_calls[2] == logging::level::USER1); } -template <> constexpr auto flow::log_spec<"C"> = user1_log_spec{}; +template <> constexpr auto flow::log_env<"C"> = user1_log_env{}; TEST_CASE("default log spec for step will use overridden log spec for flow", "[flow_custom_log_levels]") {