From f3ecf7c61c0c5545c3a13ba891a04708315d97b9 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sat, 13 Jan 2024 18:39:57 +0800 Subject: [PATCH] Refactor logging code and update test cases --- include/libimp/log.h | 26 ++++++++++++++++++-------- test/imp/test_imp_log.cpp | 10 +++++----- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/libimp/log.h b/include/libimp/log.h index 7ceee10..0efeeec 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -106,20 +106,30 @@ inline auto &make_std_out() noexcept { } /** - * \brief Log information grips. + * \brief Log information base class. */ -template -class logger { - Outputer out_; +class logger_base { +protected: char const *func_; level level_limit_; + logger_base(char const *func, level level_limit) noexcept + : func_ (func) + , level_limit_(level_limit) {} +}; + +/** + * \brief Log information grips. + */ +template +class logger : public logger_base { + Outputer out_; + public: template - logger(char const *func, O &&out, level level_limit) noexcept - : out_ (std::forward(out)) - , func_ (func) - , level_limit_(level_limit) {} + logger(char const *func, O &&out, level level_limit) noexcept + : logger_base(func, level_limit) + , out_ (std::forward(out)) {} template logger const &operator()(log::level l, A &&...args) const noexcept { diff --git a/test/imp/test_imp_log.cpp b/test/imp/test_imp_log.cpp index 206e27d..1d5bd9b 100644 --- a/test/imp/test_imp_log.cpp +++ b/test/imp/test_imp_log.cpp @@ -17,7 +17,7 @@ TEST(log, logger) { } { LIBIMP_LOG_(); - log.info(), "hello ", 3; + log.info("hello ", 3); } SUCCEED(); } @@ -36,11 +36,11 @@ TEST(log, custom) { LIBIMP_LOG_(ll); - log.info ("hello"); - log.error("failed:"); - log.info ("log-pt"); + log.info ("hello", " world"); + log.error("failed", ":"); + log.info ("log", '-', "pt"); log.error("whatever"); - EXPECT_EQ(ll_data.i, "hello log-pt "); + EXPECT_EQ(ll_data.i, "hello world log-pt "); EXPECT_EQ(ll_data.e, "failed: whatever "); }