mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
parent
51bcff820e
commit
4641347c3f
@ -7,13 +7,20 @@
|
||||
#if defined(_WIN32)
|
||||
|
||||
# include <spdlog/details/null_mutex.h>
|
||||
# if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
# include <spdlog/details/os.h>
|
||||
# endif
|
||||
# include <spdlog/sinks/base_sink.h>
|
||||
|
||||
# include <mutex>
|
||||
# include <string>
|
||||
|
||||
// Avoid including windows.h (https://stackoverflow.com/a/30741042)
|
||||
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString);
|
||||
#else
|
||||
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
|
||||
#endif
|
||||
extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
|
||||
|
||||
namespace spdlog {
|
||||
@ -38,8 +45,14 @@ protected:
|
||||
}
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
formatted.push_back('\0'); // add a null terminator for OutputDebugStringA
|
||||
formatted.push_back('\0'); // add a null terminator for OutputDebugString
|
||||
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
wmemory_buf_t wformatted;
|
||||
details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted);
|
||||
OutputDebugStringW(wformatted.data());
|
||||
#else
|
||||
OutputDebugStringA(formatted.data());
|
||||
#endif
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
Loading…
Reference in New Issue
Block a user