mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Fixed wchar support in messages
This commit is contained in:
parent
898e1f2641
commit
81f29a9a7a
@ -18,7 +18,7 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#endif
|
||||
|
@ -173,24 +173,25 @@ inline void spdlog::logger::critical(const T &msg)
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *msg)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
|
||||
|
||||
log(lvl, conv.to_bytes(msg));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
fmt::WMemoryWriter wWriter;
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
decltype(wstring_converter_)::byte_string utf8_string;
|
||||
|
||||
wWriter.write(fmt, args...);
|
||||
log(lvl, wWriter.c_str());
|
||||
try
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(wstring_converter_mutex_);
|
||||
utf8_string = wstring_converter_.to_bytes(fmt);
|
||||
}
|
||||
log(lvl, utf8_string.c_str(), args...);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
|
@ -63,10 +63,7 @@ public:
|
||||
template<typename... Args>
|
||||
void critical(const char *fmt, const Args &... args);
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, const wchar_t *msg);
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, const wchar_t *fmt, const Args &... args);
|
||||
|
||||
@ -152,6 +149,11 @@ protected:
|
||||
log_err_handler err_handler_;
|
||||
std::atomic<time_t> last_err_time_;
|
||||
std::atomic<size_t> msg_counter_;
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_converter_;
|
||||
std::mutex wstring_converter_mutex_;
|
||||
#endif
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user