From af96a09e36a44f61d9f8c582a08b1dff9505fc0a Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 28 May 2023 13:01:09 +0800 Subject: [PATCH] upd: [imp] output interface of the log should be const --- include/libimp/log.h | 28 ++++++++++++++-------------- test/imp/test_imp_log.cpp | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/libimp/log.h b/include/libimp/log.h index 7bb0798..4231a40 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -114,8 +114,15 @@ class grip { char const *func_; level level_limit_; +public: + template + grip(char const *func, O &&out, level level_limit) noexcept + : out_ (std::forward(out)) + , func_ (func) + , level_limit_(level_limit) {} + template - grip &output(log::level l, A &&... args) noexcept { + grip const &operator()(log::level l, A &&... args) const noexcept { if (underlyof(l) < underlyof(level_limit_)) { return *this; } @@ -128,19 +135,12 @@ class grip { return *this; } -public: - template - grip(char const *func, O &&out, level level_limit) noexcept - : out_ (std::forward(out)) - , func_ (func) - , level_limit_(level_limit) {} - - template grip &trace (A &&...args) noexcept { return output(log::level::trace , std::forward(args)...); } - template grip &debug (A &&...args) noexcept { return output(log::level::debug , std::forward(args)...); } - template grip &info (A &&...args) noexcept { return output(log::level::info , std::forward(args)...); } - template grip &warning(A &&...args) noexcept { return output(log::level::warning, std::forward(args)...); } - template grip &error (A &&...args) noexcept { return output(log::level::error , std::forward(args)...); } - template grip &failed (A &&...args) noexcept { return output(log::level::failed , std::forward(args)...); } + template grip const &trace (A &&...args) const noexcept { return (*this)(log::level::trace , std::forward(args)...); } + template grip const &debug (A &&...args) const noexcept { return (*this)(log::level::debug , std::forward(args)...); } + template grip const &info (A &&...args) const noexcept { return (*this)(log::level::info , std::forward(args)...); } + template grip const &warning(A &&...args) const noexcept { return (*this)(log::level::warning, std::forward(args)...); } + template grip const &error (A &&...args) const noexcept { return (*this)(log::level::error , std::forward(args)...); } + template grip const &failed (A &&...args) const noexcept { return (*this)(log::level::failed , std::forward(args)...); } }; template diff --git a/test/imp/test_imp_log.cpp b/test/imp/test_imp_log.cpp index 93e89a7..05a9ee7 100644 --- a/test/imp/test_imp_log.cpp +++ b/test/imp/test_imp_log.cpp @@ -23,7 +23,7 @@ TEST(log, custom) { std::string i; std::string e; } ll_data; - auto ll = [&ll_data](auto &&ctx) mutable { + auto ll = [&ll_data](auto &&ctx) { auto s = imp::fmt(ctx.params); if (ctx.level == imp::log::level::error) ll_data.e += s + " "; else