From fff6d8f3887d3c6064cfd4ec598a5e2f7b8dae03 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 31 Mar 2014 02:24:11 +0300 Subject: [PATCH] nice logger api improvement --- example/example.cpp | 2 +- include/c11log/logger.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/example/example.cpp b/example/example.cpp index a83bea24..4b138fd0 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -21,7 +21,7 @@ int main(int argc, char* argv[]) const unsigned int howmany = argc <= 1 ? 1000000:atoi(argv[1]); logger cout_logger ("", sinks::stdout_sink()); - cout_logger.info("Hello ") << "man" << 123 << " : " << 0.45f; + cout_logger.info() << "Hello " << "man" << 123 << " : " << 0.45f; cout_logger.info("This is very nice! ") << "Yes gabi.." << ":)"; auto fsink = std::make_shared("log", "txt", 1024*1024*50 , 5, 0); diff --git a/include/c11log/logger.h b/include/c11log/logger.h index 1a9779f4..51bf16e9 100644 --- a/include/c11log/logger.h +++ b/include/c11log/logger.h @@ -57,6 +57,13 @@ public: template details::line_logger critical(const T&); template details::line_logger fatal(const T&); + details::line_logger debug(); + details::line_logger info(); + details::line_logger warn(); + details::line_logger error(); + details::line_logger critical(); + details::line_logger fatal(); + private: friend details::line_logger; @@ -139,6 +146,32 @@ inline c11log::details::line_logger c11log::logger::fatal(const T& msg) return l; } +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::info() +{ + return details::line_logger(this, level::INFO, should_log(level::INFO)); +} + +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 c11log::details::line_logger c11log::logger::fatal() +{ + return details::line_logger(this, level::FATAL, should_log(level::FATAL)); +} + + inline const std::string& c11log::logger::get_name() const { return _logger_name;