From 0be8981058c744dc3840658438de97dc637543c5 Mon Sep 17 00:00:00 2001 From: gabi Date: Tue, 14 Oct 2014 04:14:35 +0300 Subject: [PATCH] logger class cleanup --- .../c11logtest/c11logtest.vcxproj.filters | 6 +- example/bench.cpp | 4 +- include/c11log/logger.h | 93 +++++-------------- 3 files changed, 29 insertions(+), 74 deletions(-) diff --git a/c11logtest/c11logtest/c11logtest.vcxproj.filters b/c11logtest/c11logtest/c11logtest.vcxproj.filters index 959b0c9d..04ad2d6f 100644 --- a/c11logtest/c11logtest/c11logtest.vcxproj.filters +++ b/c11logtest/c11logtest/c11logtest.vcxproj.filters @@ -90,12 +90,12 @@ Header Files\c11log - - Header Files\c11log\sinks - Header Files\c11log\details + + Header Files\c11log + diff --git a/example/bench.cpp b/example/bench.cpp index ec18ee1a..882f3e34 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -21,7 +21,7 @@ int main(int argc, char* argv[]) const unsigned int howmany = argc <= 1 ? 500000 : atoi(argv[1]); std::string pattern = "%Y:%m:%d %H:%M:%S.%e [%n:%l] %t"; - auto formatter1 = std::unique_ptr(new formatters::pattern_formatter(pattern)); + auto formatter1 = std::unique_ptr(new pattern_formatter(pattern)); logger cout_logger("bench", std::make_shared() , std::move(formatter1)); cout_logger.info() << "Hello logger"; @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) auto nullsink = std::make_shared>(); - auto formatter2 = std::unique_ptr(new formatters::pattern_formatter(pattern)); + auto formatter2 = std::unique_ptr(new pattern_formatter(pattern)); logger my_logger("my_logger", nullsink, std::move(formatter2)); //logger my_logger("my_logger", nullsink); diff --git a/include/c11log/logger.h b/include/c11log/logger.h index 2461ce6c..b9bada9a 100644 --- a/include/c11log/logger.h +++ b/include/c11log/logger.h @@ -47,22 +47,14 @@ public: const std::string& name() const; bool should_log(level::level_enum) const; + template details::line_logger log(level::level_enum lvl, const Args&... args); - - template details::line_logger trace(const T&); - template details::line_logger debug(const T&); + template details::line_logger trace(const Args&... args); + template details::line_logger debug(const Args&... args); template details::line_logger info(const Args&... args); - - template details::line_logger warn(const T&); - template details::line_logger error(const T&); - template details::line_logger critical(const T&); - - details::line_logger trace(); - details::line_logger debug(); - details::line_logger warn(); - details::line_logger& error(); - details::line_logger critical(); - + template details::line_logger warn(const Args&... args); + template details::line_logger error(const Args&... args); + template details::line_logger critical(const Args&... args); @@ -126,27 +118,10 @@ inline c11log::logger::logger(const std::string& name, It begin, It end, formatt } - inline c11log::logger::logger(const std::string& name, sink_ptr sink, formatter_ptr f) : logger(name, {sink}, std::move(f)) {} -template -inline c11log::details::line_logger c11log::logger::trace(const T& msg) -{ - details::line_logger l(this, level::TRACE, should_log(level::TRACE)); - l.write(msg); - return l; -} - -template -inline c11log::details::line_logger c11log::logger::debug(const T& msg) -{ - c11log::details::line_logger l(this, level::DEBUG, should_log(level::DEBUG)); - l.write(msg); - return l; -} - template inline c11log::details::line_logger c11log::logger::log(level::level_enum lvl, const Args&... args) { details::line_logger l(this, lvl, true); @@ -154,55 +129,35 @@ inline c11log::details::line_logger c11log::logger::log(level::level_enum lvl, c return l; } + +template +inline c11log::details::line_logger c11log::logger::trace(const Args&... args) { + return log(level::TRACE, args...); +} + +template +inline c11log::details::line_logger c11log::logger::debug(const Args&... args) { + return log(level::DEBUG, args...); +} + template inline c11log::details::line_logger c11log::logger::info(const Args&... args) { - details::line_logger l(this, level::INFO, should_log(level::INFO)); - _variadic_log(l, args...); - return l; + return log(level::INFO, args...); } -template -inline c11log::details::line_logger c11log::logger::warn(const T& msg) -{ - details::line_logger l(this, level::WARNING, should_log(level::WARNING)); - l.write(msg); - return l; +template +inline c11log::details::line_logger c11log::logger::warn(const Args&... args) { + return log(level::WARNING, args...); } -template -inline c11log::details::line_logger c11log::logger::critical(const T& msg) -{ - details::line_logger l(this, level::CRITICAL, should_log(level::CRITICAL)); - l.write(msg); - return l; +template +inline c11log::details::line_logger c11log::logger::critical(const Args&... args) { + return log(level::CRITICAL, args...); } - -inline c11log::details::line_logger c11log::logger::trace() -{ - return details::line_logger(this, level::TRACE, should_log(level::TRACE)); -} - -inline c11log::details::line_logger c11log::logger::debug() -{ - return details::line_logger(this, level::DEBUG, should_log(level::DEBUG)); -} - - -inline c11log::details::line_logger c11log::logger::warn() -{ - return details::line_logger(this, level::WARNING, should_log(level::WARNING)); -} - -inline c11log::details::line_logger c11log::logger::critical() -{ - return details::line_logger(this, level::CRITICAL, should_log(level::CRITICAL)); -} - - inline const std::string& c11log::logger::name() const { return _name;