mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 10:31:34 +08:00
Update stdout_sinks-inl.h
This commit is contained in:
parent
3e689e700e
commit
7828a065bf
@ -48,15 +48,14 @@ SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
|||||||
template<typename ConsoleMutex>
|
template<typename ConsoleMutex>
|
||||||
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
|
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
if (handle_ == INVALID_HANDLE_VALUE)
|
if (handle_ == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<mutex_t> lock(mutex_);
|
std::lock_guard<mutex_t> lock(mutex_);
|
||||||
memory_buf_t formatted;
|
memory_buf_t formatted;
|
||||||
formatter_->format(msg, formatted);
|
formatter_->format(msg, formatted);
|
||||||
#ifdef _WIN32
|
|
||||||
::fflush(file_); // flush in case there is somthing in this file_ already
|
::fflush(file_); // flush in case there is somthing in this file_ already
|
||||||
auto size = static_cast<DWORD>(formatted.size());
|
auto size = static_cast<DWORD>(formatted.size());
|
||||||
DWORD bytes_written = 0;
|
DWORD bytes_written = 0;
|
||||||
@ -66,6 +65,9 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
|
|||||||
throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " + std::to_string(::GetLastError()));
|
throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " + std::to_string(::GetLastError()));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
std::lock_guard<mutex_t> lock(mutex_);
|
||||||
|
memory_buf_t formatted;
|
||||||
|
formatter_->format(msg, formatted);
|
||||||
::fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
::fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
||||||
::fflush(file_); // flush every line to terminal
|
::fflush(file_); // flush every line to terminal
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
Loading…
Reference in New Issue
Block a user