From 19aff4691b1844c91bbb2955f919bba2eeed08b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Webj=C3=B6rn?= Date: Thu, 15 Sep 2016 10:33:55 +0200 Subject: [PATCH 1/2] New log function to enable wrappers with local filters --- include/spdlog/details/logger_impl.h | 28 ++++++++++++++++++++-------- include/spdlog/logger.h | 3 +++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index a337b359..7a9476b1 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -59,10 +59,8 @@ inline void spdlog::logger::set_pattern(const std::string& pattern) template -inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Args&... args) +inline void spdlog::logger::log_nofilter(level::level_enum lvl, const char* fmt, const Args&... args) { - if (!should_log(lvl)) return; - try { details::log_msg log_msg(&_name, lvl); @@ -80,9 +78,8 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar } template -inline void spdlog::logger::log(level::level_enum lvl, const char* msg) +inline void spdlog::logger::log_nofilter(level::level_enum lvl, const char* msg) { - if (!should_log(lvl)) return; try { details::log_msg log_msg(&_name, lvl); @@ -97,13 +94,11 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* msg) { _err_handler("Unknown exception"); } - } template -inline void spdlog::logger::log(level::level_enum lvl, const T& msg) +inline void spdlog::logger::log_nofilter(level::level_enum lvl, const T& msg) { - if (!should_log(lvl)) return; try { details::log_msg log_msg(&_name, lvl); @@ -120,6 +115,23 @@ inline void spdlog::logger::log(level::level_enum lvl, const T& msg) } } +template +inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Args&... args) +{ + if (should_log(lvl)) log_nofilter(lvl, fmt, args...); +} + +template +inline void spdlog::logger::log(level::level_enum lvl, const char* msg) +{ + if (should_log(lvl)) log_nofilter(lvl, msg); +} + +template +inline void spdlog::logger::log(level::level_enum lvl, const T& msg) +{ + if (should_log(lvl)) log_nofilter(lvl, msg); +} template inline void spdlog::logger::trace(const char* fmt, const Args&... args) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index e998999e..f69fbd5c 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -37,6 +37,8 @@ public: template void log(level::level_enum lvl, const char* fmt, const Args&... args); template void log(level::level_enum lvl, const char* msg); + template void log_nofilter(level::level_enum lvl, const char* fmt, const Args&... args); + template void log_nofilter(level::level_enum lvl, const char* msg); template void trace(const char* fmt, const Args&... args); template void debug(const char* fmt, const Args&... args); template void info(const char* fmt, const Args&... args); @@ -45,6 +47,7 @@ public: template void critical(const char* fmt, const Args&... args); template void log(level::level_enum lvl, const T&); + template void log_nofilter(level::level_enum lvl, const T&); template void trace(const T&); template void debug(const T&); template void info(const T&); From c4fa9cb603494699d4ffbf20f69e88c27b26192a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Webj=C3=B6rn?= Date: Fri, 30 Sep 2016 13:27:04 +0200 Subject: [PATCH 2/2] Enable build on Alpine Linux --- include/spdlog/details/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 6d27bc39..c7b2f45b 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -344,7 +344,7 @@ inline std::string errno_str(int err_num) return "Unkown error"; #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(ANDROID) || \ - ((_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE) // posix version + ((_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE) || !defined(__GLIBC__) // posix version if (strerror_r(err_num, buf, buf_size) == 0) return std::string(buf);