Commit 9a189bad authored by Asit Kumar Dhal's avatar Asit Kumar Dhal

conditional logging implementation

parent d3e013a5
...@@ -146,6 +146,15 @@ inline void spdlog::logger::warn(const char* fmt, const Arg1 &arg1, const Args&. ...@@ -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) ...@@ -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)
{ {
......
...@@ -43,6 +43,8 @@ public: ...@@ -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: ...@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment