diff --git a/include/spdlog/sinks/wincolor_sink-inl.h b/include/spdlog/sinks/wincolor_sink-inl.h index 924b8f57..0c0bb1de 100644 --- a/include/spdlog/sinks/wincolor_sink-inl.h +++ b/include/spdlog/sinks/wincolor_sink-inl.h @@ -26,7 +26,7 @@ SPDLOG_INLINE wincolor_sink::wincolor_sink(void *out_handle, color // ::GetConsoleMode() should return 0 if it is redirected or not valid console handle. DWORD console_mode; in_console_ = ::GetConsoleMode(static_cast(out_handle_), &console_mode) != 0; - set_color_mode(mode); + set_color_mode_impl(mode); // set level colors colors_[level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white @@ -112,18 +112,14 @@ void SPDLOG_INLINE wincolor_sink::set_formatter(std::unique_ptr void SPDLOG_INLINE wincolor_sink::set_color_mode(color_mode mode) { - switch (mode) - { - case color_mode::always: - case color_mode::automatic: - should_do_colors_ = true; - break; - case color_mode::never: - should_do_colors_ = false; - break; - default: - should_do_colors_ = true; - } + std::lock_guard lock(mutex_); + set_color_mode_impl(mode); +} + +template +void SPDLOG_INLINE wincolor_sink::set_color_mode_impl(color_mode mode) +{ + should_do_colors_ = mode != color_mode::never; } // set foreground color and return the orig console attributes (for resetting later) diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index 3b01121b..d85721f2 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -55,6 +55,8 @@ protected: // in case we are redirected to file (not in console mode) void write_to_file_(const memory_buf_t &formatted); + + void set_color_mode_impl(color_mode mode); }; template