From d0dcc13f7c265bd86e926f260b08ed3dffc10a58 Mon Sep 17 00:00:00 2001 From: gabi Date: Mon, 8 Dec 2014 00:09:54 +0200 Subject: [PATCH] small cleanup --- include/spdlog/details/line_logger.h | 22 ++++++++++++---------- include/spdlog/details/logger_impl.h | 21 ++++++--------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/include/spdlog/details/line_logger.h b/include/spdlog/details/line_logger.h index 2a2bd2af..cf54bb79 100644 --- a/include/spdlog/details/line_logger.h +++ b/include/spdlog/details/line_logger.h @@ -69,25 +69,27 @@ public: } } - template - void write(const T& what) - { - if (_enabled) - { - _log_msg.raw << what; - } - } template void write(const std::string& fmt, const Args&... args) { - _log_msg.raw.write(fmt, args...); + if (!_enabled) + return; + try + { + _log_msg.raw.write(fmt, args...); + } + catch (const fmt::FormatError& e) + { + throw spdlog_ex(fmt::format("formatting error while processing format string '{}': {}", fmt, e.what())); + } } template line_logger& operator<<(const T& what) { - write(what); + if (_enabled) + _log_msg.raw << what; return *this; } diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 62e8a6e5..286dde48 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -71,18 +71,7 @@ inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl, { bool msg_enabled = should_log(lvl); details::line_logger l(this, lvl, msg_enabled); - if (msg_enabled) - { - try - { - l.write(fmt, args...); - } - catch(const fmt::FormatError& e) - { - throw spdlog_ex(fmt::format("formatting error while processing format string '{}': {}", fmt, e.what())); - } - - } + l.write(fmt, args...); return l; } @@ -151,7 +140,6 @@ inline spdlog::details::line_logger spdlog::logger::emerg(const std::string& fmt // //API to support logger.info() << ".." calls // - inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl) { bool msg_enabled = should_log(lvl); @@ -213,7 +201,8 @@ inline spdlog::details::line_logger spdlog::logger::emerg() // - +// name and level +// inline const std::string& spdlog::logger::name() const { return _name; @@ -239,7 +228,9 @@ inline void spdlog::logger::stop() _stop(); } -/* protected virtual */ +// +// protected virtual called at end of each user log call (if enabled) by the line_logger +// inline void spdlog::logger::_log_msg(details::log_msg& msg) { _formatter->format(msg);