Commit b463b06a authored by Asit Kumar Dhal's avatar Asit Kumar Dhal

conditional logging for all levels

parents 9a189bad ed7c3a83
...@@ -146,7 +146,64 @@ inline void spdlog::logger::warn(const char* fmt, const Arg1 &arg1, const Args&. ...@@ -146,7 +146,64 @@ 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> template <typename Arg1, typename... Args>
inline void spdlog::logger::error(const char* fmt, const Arg1 &arg1, const Args&... args)
{
log(level::err, fmt, arg1, args...);
}
template <typename Arg1, typename... Args>
inline void spdlog::logger::critical(const char* fmt, const Arg1 &arg1, const Args&... args)
{
log(level::critical, fmt, arg1, args...);
}
template <typename... Args>
inline void spdlog::logger::log_if(const bool flag, level::level_enum lvl, const char* msg)
{
if (flag)
{
log(lvl, msg);
}
}
template<typename T>
inline void spdlog::logger::log_if(const bool flag, level::level_enum lvl, const T& msg)
{
if (flag)
{
log(lvl, msg);
}
}
template <typename Arg1, typename... Args>
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 <typename Arg1, typename... Args>
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 <typename Arg1, typename... Args>
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 <typename Arg1, typename... Args>
inline void spdlog::logger::warn_if(const bool flag, const char* fmt, const Arg1& arg1, const Args&... args) inline void spdlog::logger::warn_if(const bool flag, const char* fmt, const Arg1& arg1, const Args&... args)
{ {
if (flag) if (flag)
...@@ -156,17 +213,24 @@ inline void spdlog::logger::warn_if(const bool flag, const char* fmt, const Arg1 ...@@ -156,17 +213,24 @@ inline void spdlog::logger::warn_if(const bool flag, const char* fmt, const Arg1
} }
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_if(const bool flag, const char* fmt, const Arg1 &arg1, const Args&... args)
{ {
log(level::err, fmt, arg1, args...); if (flag)
{
log(level::err, fmt, arg1, args...);
}
} }
template <typename Arg1, typename... Args> template <typename Arg1, typename... Args>
inline void spdlog::logger::critical(const char* fmt, const Arg1 &arg1, const Args&... args) inline void spdlog::logger::critical_if(const bool flag, const char* fmt, const Arg1 &arg1, const Args&... args)
{ {
log(level::critical, fmt, arg1, args...); if (flag)
{
log(level::critical, fmt, arg1, args...);
}
} }
template<typename T> template<typename T>
inline void spdlog::logger::trace(const T& msg) inline void spdlog::logger::trace(const T& msg)
{ {
...@@ -193,6 +257,45 @@ inline void spdlog::logger::warn(const T& msg) ...@@ -193,6 +257,45 @@ inline void spdlog::logger::warn(const T& msg)
log(level::warn, msg); log(level::warn, msg);
} }
template<typename T>
inline void spdlog::logger::error(const T& msg)
{
log(level::err, msg);
}
template<typename T>
inline void spdlog::logger::critical(const T& msg)
{
log(level::critical, msg);
}
template<typename T>
inline void spdlog::logger::trace_if(const bool flag, const T& msg)
{
if (flag)
{
log(level::trace, msg);
}
}
template<typename T>
inline void spdlog::logger::debug_if(const bool flag, const T& msg)
{
if (flag)
{
log(level::debug, msg);
}
}
template<typename T>
inline void spdlog::logger::info_if(const bool flag, const T& msg)
{
if (flag)
{
log(level::info, msg);
}
}
template<typename T> template<typename T>
inline void spdlog::logger::warn_if(const bool flag, const T& msg) inline void spdlog::logger::warn_if(const bool flag, const T& msg)
{ {
...@@ -203,17 +306,24 @@ inline void spdlog::logger::warn_if(const bool flag, const T& msg) ...@@ -203,17 +306,24 @@ inline void spdlog::logger::warn_if(const bool flag, const T& msg)
} }
template<typename T> template<typename T>
inline void spdlog::logger::error(const T& msg) inline void spdlog::logger::error_if(const bool flag, const T& msg)
{ {
log(level::err, msg); if (flag)
{
log(level::error, msg);
}
} }
template<typename T> template<typename T>
inline void spdlog::logger::critical(const T& msg) inline void spdlog::logger::critical_if(const bool flag, const T& msg)
{ {
log(level::critical, msg); if (flag)
{
log(level::critical, msg);
}
} }
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
#include <codecvt> #include <codecvt>
......
...@@ -43,8 +43,16 @@ public: ...@@ -43,8 +43,16 @@ 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... Args> void log_if(const bool flag, level::level_enum lvl, const char* fmt, const Args&... args);
template <typename... Args> void log_if(const bool flag, level::level_enum lvl, const char* msg);
template <typename Arg1, typename... Args> void trace_if(const bool flag, const char* fmt, const Arg1&, const Args&... args);
template <typename Arg1, typename... Args> void debug_if(const bool flag, const char* fmt, const Arg1&, const Args&... args);
template <typename Arg1, typename... Args> void info_if(const bool flag, 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); template <typename Arg1, typename... Args> void warn_if(const bool flag, const char* fmt, const Arg1&, const Args&... args);
template <typename Arg1, typename... Args> void error_if(const bool flag, const char* fmt, const Arg1&, const Args&... args);
template <typename Arg1, typename... Args> void critical_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);
...@@ -54,6 +62,15 @@ public: ...@@ -54,6 +62,15 @@ public:
template <typename... Args> void warn(const wchar_t* fmt, const Args&... args); template <typename... Args> void warn(const wchar_t* fmt, const Args&... args);
template <typename... Args> void error(const wchar_t* fmt, const Args&... args); template <typename... Args> void error(const wchar_t* fmt, const Args&... args);
template <typename... Args> void critical(const wchar_t* fmt, const Args&... args); template <typename... Args> void critical(const wchar_t* fmt, const Args&... args);
template <typename... Args> void log_if(const bool flag, level::level_enum lvl, const wchar_t* msg);
template <typename... Args> void log_if(const bool flag, level::level_enum lvl, const wchar_t* fmt, const Args&... args);
template <typename... Args> void trace_if(const bool flag, const wchar_t* fmt, const Args&... args);
template <typename... Args> void debug_if(const bool flag, const wchar_t* fmt, const Args&... args);
template <typename... Args> void info_if(const bool flag, const wchar_t* fmt, const Args&... args);
template <typename... Args> void warn_if(const bool flag, const wchar_t* fmt, const Args&... args);
template <typename... Args> void error_if(const bool flag, const wchar_t* fmt, const Args&... args);
template <typename... Args> void critical_if(const bool flag, const wchar_t* fmt, const Args&... args);
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
template <typename T> void log(level::level_enum lvl, const T&); template <typename T> void log(level::level_enum lvl, const T&);
...@@ -64,7 +81,13 @@ public: ...@@ -64,7 +81,13 @@ 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 log_if(const bool flag, level::level_enum lvl, const T&);
template <typename T> void trace_if(const bool flag, const T&);
template <typename T> void debug_if(const bool flag, const T&);
template <typename T> void info_if(const bool flag, const T&);
template <typename T> void warn_if(const bool flag, const T&); template <typename T> void warn_if(const bool flag, const T&);
template <typename T> void error_if(const bool flag, const T&);
template <typename T> void critical_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);
......
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