diff --git a/include/spdlog/sinks/stdout_sinks-inl.h b/include/spdlog/sinks/stdout_sinks-inl.h index e5aacd5b..83cb1f4d 100644 --- a/include/spdlog/sinks/stdout_sinks-inl.h +++ b/include/spdlog/sinks/stdout_sinks-inl.h @@ -49,7 +49,11 @@ SPDLOG_INLINE void stdout_sink_base::log(const details::log_msg &m #ifdef _WIN32 auto size = static_cast(formatted.size()); DWORD bytes_written = 0; - ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr); + bool ok = ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr) != 0; + if (!ok) + { + throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " + std::to_string(::GetLastError())); + } #else ::fwrite(formatted.data(), sizeof(char), formatted.size(), file_); ::fflush(file_); // flush every line to terminal diff --git a/include/spdlog/sinks/wincolor_sink-inl.h b/include/spdlog/sinks/wincolor_sink-inl.h index 1551c902..587720ac 100644 --- a/include/spdlog/sinks/wincolor_sink-inl.h +++ b/include/spdlog/sinks/wincolor_sink-inl.h @@ -155,7 +155,7 @@ void SPDLOG_INLINE wincolor_sink::write_to_file_(const memory_buf_ bool ok = ::WriteFile(out_handle_, formatted.data(), size, &bytes_written, nullptr) != 0; if (!ok) { - throw_spdlog_ex("wincolor_sink: write_to_file_ failed. GetLastError(): " + std::to_string(::GetLastError())); + throw_spdlog_ex("wincolor_sink: ::WriteFile() failed. GetLastError(): " + std::to_string(::GetLastError())); } }