From 2ce9a3f70fa9e85d1e3bd158bc686ec22c5e95bb Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Wed, 24 Jul 2019 13:27:54 -0400 Subject: [PATCH] Add overload to logger when T can be statically converted to wstring_view_t --- include/spdlog/logger.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 8d991e58..69e3721f 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -228,7 +228,7 @@ public: fmt::format_to(wbuf, fmt, args...); fmt::memory_buffer buf; - details::os::wstr_to_utf8buf(basic_string_view_t(wbuf.data(), wbuf.size()), buf); + details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf); details::log_msg log_msg(source, name_, lvl, string_view_t(buf.data(), buf.size())); sink_it_(log_msg); @@ -277,6 +277,26 @@ public: { log(level::critical, fmt, args...); } + + // T can be statically converted to wstring_view + template::value, T>::type * = nullptr> + void log(source_loc loc, level::level_enum lvl, const T &msg) + { + if (!should_log(lvl)) + { + return; + } + + try + { + fmt::memory_buffer buf; + details::os::wstr_to_utf8buf(msg, buf); + + details::log_msg log_msg(loc, name_, lvl, buf); + sink_it_(log_msg); + } + SPDLOG_LOGGER_CATCH() + } #endif // _WIN32 #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT