Updatd WriteFile usage

This commit is contained in:
gabime 2020-09-27 18:34:01 +03:00
parent cfd0ea197c
commit 680fb07fd5
2 changed files with 6 additions and 2 deletions

View File

@ -49,7 +49,11 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
#ifdef _WIN32
auto size = static_cast<DWORD>(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

View File

@ -155,7 +155,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::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()));
}
}