conditional logging implementation

This commit is contained in:
Asit Kumar Dhal 2017-06-17 02:45:24 +02:00
parent d3e013a567
commit 9a189badbd
2 changed files with 22 additions and 0 deletions

View File

@ -146,6 +146,15 @@ inline void spdlog::logger::warn(const char* fmt, const Arg1 &arg1, const Args&.
log(level::warn, fmt, arg1, args...); log(level::warn, fmt, arg1, args...);
} }
template <typename Arg1, typename... Args>
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 <typename Arg1, typename... Args> template <typename Arg1, typename... Args>
inline void spdlog::logger::error(const char* fmt, const Arg1 &arg1, const Args&... args) 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); log(level::warn, msg);
} }
template<typename T>
inline void spdlog::logger::warn_if(const bool flag, const T& msg)
{
if (flag)
{
log(level::warn, msg);
}
}
template<typename T> template<typename T>
inline void spdlog::logger::error(const T& msg) inline void spdlog::logger::error(const T& msg)
{ {

View File

@ -43,6 +43,8 @@ public:
template <typename Arg1, typename... Args> void warn(const char* fmt, const Arg1&, const Args&... args); template <typename Arg1, typename... Args> void warn(const char* fmt, const Arg1&, const Args&... args);
template <typename Arg1, typename... Args> void error(const char* fmt, const Arg1&, const Args&... args); template <typename Arg1, typename... Args> void error(const char* fmt, const Arg1&, const Args&... args);
template <typename Arg1, typename... Args> void critical(const char* fmt, const Arg1&, const Args&... args); template <typename Arg1, typename... Args> void critical(const char* fmt, const Arg1&, const Args&... args);
template <typename Arg1, typename... Args> void warn_if(const bool flag, const char* fmt, const Arg1&, const Args&... args);
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template <typename... Args> void log(level::level_enum lvl, const wchar_t* msg); template <typename... Args> void log(level::level_enum lvl, const wchar_t* msg);
template <typename... Args> void log(level::level_enum lvl, const wchar_t* fmt, const Args&... args); template <typename... Args> void log(level::level_enum lvl, const wchar_t* fmt, const Args&... args);
@ -62,6 +64,8 @@ public:
template <typename T> void error(const T&); template <typename T> void error(const T&);
template <typename T> void critical(const T&); template <typename T> void critical(const T&);
template <typename T> void warn_if(const bool flag, const T&);
bool should_log(level::level_enum) const; bool should_log(level::level_enum) const;
void set_level(level::level_enum); void set_level(level::level_enum);
level::level_enum level() const; level::level_enum level() const;