From ed7c3a83f837ac00a6da3cd4246fa96166f48810 Mon Sep 17 00:00:00 2001 From: Asit Kumar Dhal Date: Sat, 17 Jun 2017 02:45:24 +0200 Subject: [PATCH] conditional logging implementation --- include/spdlog/details/logger_impl.h | 18 ++++++++++++++++++ include/spdlog/logger.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index c6aa125b..2b0c2d8f 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -146,6 +146,15 @@ inline void spdlog::logger::warn(const char* fmt, const Arg1 &arg1, const Args&. log(level::warn, fmt, arg1, args...); } +template +inline void spdlog::logger::warn_if(const bool flag, const char* fmt, const Arg1& arg1, const Args&... args) +{ + if (flag) + { + log(level::warn, fmt, arg1, args...); + } +} + template inline void spdlog::logger::error(const char* fmt, const Arg1 &arg1, const Args&... args) { @@ -184,6 +193,15 @@ inline void spdlog::logger::warn(const T& msg) log(level::warn, msg); } +template +inline void spdlog::logger::warn_if(const bool flag, const T& msg) +{ + if (flag) + { + log(level::warn, msg); + } +} + template inline void spdlog::logger::error(const T& msg) { diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index fce99f9a..9f38332c 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -43,6 +43,8 @@ public: template void warn(const char* fmt, const Arg1&, const Args&... args); template void error(const char* fmt, const Arg1&, const Args&... args); template void critical(const char* fmt, const Arg1&, const Args&... args); + + template void warn_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT template void log(level::level_enum lvl, const wchar_t* msg); template void log(level::level_enum lvl, const wchar_t* fmt, const Args&... args); @@ -62,6 +64,8 @@ public: template void error(const T&); template void critical(const T&); + template void warn_if(const bool flag, const T&); + bool should_log(level::level_enum) const; void set_level(level::level_enum); level::level_enum level() const;