diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index e9b7a8e8..8af8177f 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -71,7 +71,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Ar } SPDLOG_CATCH_AND_HANDLE } - +template<> inline void spdlog::logger::log(level::level_enum lvl, const char *msg) { if (!should_log(lvl)) @@ -81,13 +81,29 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg) try { - details::log_msg log_msg(&name_, lvl, msg); + details::log_msg log_msg(&name_, lvl, spdlog::string_view_type(msg)); sink_it_(log_msg); } SPDLOG_CATCH_AND_HANDLE } -template + +template::value, T>::type *> +inline void spdlog::logger::log(level::level_enum lvl, const T &msg) +{ + if (!should_log(lvl)) + { + return; + } + try + { + details::log_msg log_msg(&name_, lvl, spdlog::string_view_type(msg)); + sink_it_(log_msg); + } + SPDLOG_CATCH_AND_HANDLE +} + +template::value, T>::type*> inline void spdlog::logger::log(level::level_enum lvl, const T &msg) { if (!should_log(lvl)) @@ -105,6 +121,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const T &msg) SPDLOG_CATCH_AND_HANDLE } + + + 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 90610a43..fd428724 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -46,6 +46,7 @@ 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 @@ -93,7 +94,12 @@ public: #endif // _WIN32 #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT - template + // T can be statically converted to string_view + template::value, T>::type * = nullptr> + void log(level::level_enum lvl, const T &); + + // T cannot be statically converted to string_view + template::value, T>::type * = nullptr> void log(level::level_enum lvl, const T &); template