1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-01-16 09:47:56 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Gabi Melman
16d78ae5db
Update stdout_sinks-inl.h 2020-09-28 17:08:13 +03:00
gabime
62b4b7af83 Fix #1667 2020-09-28 13:39:31 +03:00
2 changed files with 6 additions and 5 deletions

View File

@ -8,12 +8,13 @@
#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h>
#include <spdlog/details/windows_include.h>
#include <winbase.h>
#include <mutex>
#include <string>
// Avoid including windows.h (https://stackoverflow.com/a/30741042)
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
namespace spdlog {
namespace sinks {
/*
@ -23,12 +24,11 @@ template<typename Mutex>
class msvc_sink : public base_sink<Mutex>
{
public:
explicit msvc_sink() {}
msvc_sink() = default;
protected:
void sink_it_(const details::log_msg &msg) override
{
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
OutputDebugStringA(fmt::to_string(formatted).c_str());

View File

@ -47,6 +47,7 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
memory_buf_t formatted;
formatter_->format(msg, formatted);
#ifdef _WIN32
::fflush(file_); // flush in case there is somthing in this file_ already
auto size = static_cast<DWORD>(formatted.size());
DWORD bytes_written = 0;
bool ok = ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr) != 0;