diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 2b0c2d8f..9ea78eb4 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -146,15 +146,6 @@ 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) { @@ -167,6 +158,79 @@ inline void spdlog::logger::critical(const char* fmt, const Arg1 &arg1, const Ar log(level::critical, fmt, arg1, args...); } +template +inline void spdlog::logger::log_if(const bool flag, level::level_enum lvl, const char* msg) +{ + if (flag) + { + log(lvl, msg); + } +} + +template +inline void spdlog::logger::log_if(const bool flag, level::level_enum lvl, const T& msg) +{ + if (flag) + { + log(lvl, msg); + } +} + +template +inline void spdlog::logger::trace_if(const bool flag, const char* fmt, const Arg1 &arg1, const Args&... args) +{ + if (flag) + { + log(level::trace, fmt, arg1, args...); + } +} + +template +inline void spdlog::logger::debug_if(const bool flag, const char* fmt, const Arg1 &arg1, const Args&... args) +{ + if (flag) + { + log(level::debug, fmt, arg1, args...); + } +} + +template +inline void spdlog::logger::info_if(const bool flag, const char* fmt, const Arg1 &arg1, const Args&... args) +{ + if (flag) + { + log(level::info, 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_if(const bool flag, const char* fmt, const Arg1 &arg1, const Args&... args) +{ + if (flag) + { + log(level::err, fmt, arg1, args...); + } +} + +template +inline void spdlog::logger::critical_if(const bool flag, const char* fmt, const Arg1 &arg1, const Args&... args) +{ + if (flag) + { + log(level::critical, fmt, arg1, args...); + } +} + + template inline void spdlog::logger::trace(const T& msg) { @@ -193,15 +257,6 @@ 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) { @@ -214,6 +269,61 @@ inline void spdlog::logger::critical(const T& msg) log(level::critical, msg); } +template +inline void spdlog::logger::trace_if(const bool flag, const T& msg) +{ + if (flag) + { + log(level::trace, msg); + } +} + +template +inline void spdlog::logger::debug_if(const bool flag, const T& msg) +{ + if (flag) + { + log(level::debug, msg); + } +} + +template +inline void spdlog::logger::info_if(const bool flag, const T& msg) +{ + if (flag) + { + log(level::info, 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_if(const bool flag, const T& msg) +{ + if (flag) + { + log(level::error, msg); + } +} + +template +inline void spdlog::logger::critical_if(const bool flag, const T& msg) +{ + if (flag) + { + log(level::critical, msg); + } +} + + #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #include diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 9f38332c..4e380a7b 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -43,8 +43,16 @@ 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 log_if(const bool flag, level::level_enum lvl, const char* fmt, const Args&... args); + template void log_if(const bool flag, level::level_enum lvl, const char* msg); + template void trace_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template void debug_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template void info_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); template void warn_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template void error_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template void critical_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); @@ -54,6 +62,15 @@ public: template void warn(const wchar_t* fmt, const Args&... args); template void error(const wchar_t* fmt, const Args&... args); template void critical(const wchar_t* fmt, const Args&... args); + + template void log_if(const bool flag, level::level_enum lvl, const wchar_t* msg); + template void log_if(const bool flag, level::level_enum lvl, const wchar_t* fmt, const Args&... args); + template void trace_if(const bool flag, const wchar_t* fmt, const Args&... args); + template void debug_if(const bool flag, const wchar_t* fmt, const Args&... args); + template void info_if(const bool flag, const wchar_t* fmt, const Args&... args); + template void warn_if(const bool flag, const wchar_t* fmt, const Args&... args); + template void error_if(const bool flag, const wchar_t* fmt, const Args&... args); + template void critical_if(const bool flag, const wchar_t* fmt, const Args&... args); #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT template void log(level::level_enum lvl, const T&); @@ -64,7 +81,13 @@ public: template void error(const T&); template void critical(const T&); + template void log_if(const bool flag, level::level_enum lvl, const T&); + template void trace_if(const bool flag, const T&); + template void debug_if(const bool flag, const T&); + template void info_if(const bool flag, const T&); template void warn_if(const bool flag, const T&); + template void error_if(const bool flag, const T&); + template void critical_if(const bool flag, const T&); bool should_log(level::level_enum) const; void set_level(level::level_enum);