Skip to content

Commit f3ecf7c

Browse files
committed
Refactor logging code and update test cases
1 parent 30e5af9 commit f3ecf7c

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

include/libimp/log.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,31 @@ inline auto &make_std_out() noexcept {
105105
return std_out;
106106
}
107107

108+
/**
109+
* \brief Log information base class.
110+
*/
111+
class logger_base {
112+
protected:
113+
char const *func_;
114+
level level_limit_;
115+
116+
logger_base(char const *func, level level_limit) noexcept
117+
: func_ (func)
118+
, level_limit_(level_limit) {}
119+
};
120+
108121
/**
109122
* \brief Log information grips.
110123
*/
111124
template <typename Outputer>
112-
class logger {
125+
class logger : public logger_base {
113126
Outputer out_;
114-
char const *func_;
115-
level level_limit_;
116127

117128
public:
118129
template <typename O>
119-
logger(char const *func, O &&out, level level_limit) noexcept
120-
: out_ (std::forward<O>(out))
121-
, func_ (func)
122-
, level_limit_(level_limit) {}
130+
logger(char const *func, O &&out, level level_limit) noexcept
131+
: logger_base(func, level_limit)
132+
, out_ (std::forward<O>(out)) {}
123133

124134
template <typename... A>
125135
logger const &operator()(log::level l, A &&...args) const noexcept {

test/imp/test_imp_log.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TEST(log, logger) {
1717
}
1818
{
1919
LIBIMP_LOG_();
20-
log.info(), "hello ", 3;
20+
log.info("hello ", 3);
2121
}
2222
SUCCEED();
2323
}
@@ -36,11 +36,11 @@ TEST(log, custom) {
3636

3737
LIBIMP_LOG_(ll);
3838

39-
log.info ("hello");
40-
log.error("failed:");
41-
log.info ("log-pt");
39+
log.info ("hello", " world");
40+
log.error("failed", ":");
41+
log.info ("log", '-', "pt");
4242
log.error("whatever");
4343

44-
EXPECT_EQ(ll_data.i, "hello log-pt ");
44+
EXPECT_EQ(ll_data.i, "hello world log-pt ");
4545
EXPECT_EQ(ll_data.e, "failed: whatever ");
4646
}

0 commit comments

Comments
 (0)