mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 17:00:25 +08:00
Fix #1828
This commit is contained in:
parent
89e737a258
commit
5efccfa5e2
@ -32,8 +32,13 @@ SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
|||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// get windows handle from the FILE* object
|
// get windows handle from the FILE* object
|
||||||
|
|
||||||
handle_ = (HANDLE)::_get_osfhandle(::_fileno(file_));
|
handle_ = (HANDLE)::_get_osfhandle(::_fileno(file_));
|
||||||
if (handle_ == INVALID_HANDLE_VALUE)
|
|
||||||
|
// don't throw to support cases where no console is attached,
|
||||||
|
// and let the log method to do nothing if (handle_ == INVALID_HANDLE_VALUE).
|
||||||
|
// throw only if non stdout/stderr target is requested (probably regular file and not console).
|
||||||
|
if (handle_ == INVALID_HANDLE_VALUE && file != stdout && file != stderr)
|
||||||
{
|
{
|
||||||
throw_spdlog_ex("spdlog::stdout_sink_base: _get_osfhandle() failed", errno);
|
throw_spdlog_ex("spdlog::stdout_sink_base: _get_osfhandle() failed", errno);
|
||||||
}
|
}
|
||||||
@ -43,6 +48,11 @@ 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)
|
||||||
{
|
{
|
||||||
|
if (handle_ == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
@ -60,7 +60,6 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
|||||||
{
|
{
|
||||||
if (out_handle_ == INVALID_HANDLE_VALUE)
|
if (out_handle_ == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
// nothing better to do if we don't have valid handle
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user