Refactor logging code and update test cases

This commit is contained in:
mutouyun 2024-01-13 18:39:57 +08:00
parent 30e5af90b3
commit f3ecf7c61c
2 changed files with 23 additions and 13 deletions

View File

@ -106,20 +106,30 @@ inline auto &make_std_out() noexcept {
}
/**
* \brief Log information grips.
* \brief Log information base class.
*/
template <typename Outputer>
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 <typename Outputer>
class logger : public logger_base {
Outputer out_;
public:
template <typename O>
logger(char const *func, O &&out, level level_limit) noexcept
: out_ (std::forward<O>(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<O>(out)) {}
template <typename... A>
logger const &operator()(log::level l, A &&...args) const noexcept {

View File

@ -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 ");
}