mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
@@ -175,6 +175,29 @@ inline void spdlog::logger::critical(const T &msg)
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
static_assert(_WIN32, "SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows");
|
||||
inline void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target)
|
||||
{
|
||||
int wbuf_size = static_cast<int>(wbuf.size());
|
||||
if (wbuf_size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto result_size = ::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, NULL, 0, NULL, NULL);
|
||||
|
||||
if (result_size > 0)
|
||||
{
|
||||
target.resize(result_size);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, &target.data()[0], result_size, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog::spdlog_ex("Failed converting to utf8", errno);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
@@ -183,15 +206,14 @@ inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const
|
||||
return;
|
||||
}
|
||||
|
||||
decltype(wstring_converter_)::byte_string utf8_string;
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(wstring_converter_mutex_);
|
||||
utf8_string = wstring_converter_.to_bytes(fmt);
|
||||
}
|
||||
log(lvl, utf8_string.c_str(), args...);
|
||||
// format to wmemory_buffer and convert to utf8
|
||||
details::log_msg log_msg(&name_, lvl);
|
||||
fmt::wmemory_buffer wbuf;
|
||||
fmt::format_to(wbuf, fmt, args...);
|
||||
wbuf_to_utf8buf(wbuf, log_msg.raw);
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user