mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-24 06:32:06 +08:00
simplifiy and mutex protect set_color_mode in wincolor sink
This commit is contained in:
parent
c47c854f15
commit
17e1ba8ae2
@ -26,7 +26,7 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color
|
|||||||
// ::GetConsoleMode() should return 0 if it is redirected or not valid console handle.
|
// ::GetConsoleMode() should return 0 if it is redirected or not valid console handle.
|
||||||
DWORD console_mode;
|
DWORD console_mode;
|
||||||
in_console_ = ::GetConsoleMode(static_cast<HANDLE>(out_handle_), &console_mode) != 0;
|
in_console_ = ::GetConsoleMode(static_cast<HANDLE>(out_handle_), &console_mode) != 0;
|
||||||
set_color_mode(mode);
|
set_color_mode_impl(mode);
|
||||||
|
|
||||||
// set level colors
|
// set level colors
|
||||||
colors_[level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
colors_[level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
||||||
@ -112,18 +112,14 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_formatter(std::unique_ptr<sp
|
|||||||
template<typename ConsoleMutex>
|
template<typename ConsoleMutex>
|
||||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||||
{
|
{
|
||||||
switch (mode)
|
std::lock_guard<mutex_t> lock(mutex_);
|
||||||
{
|
set_color_mode_impl(mode);
|
||||||
case color_mode::always:
|
}
|
||||||
case color_mode::automatic:
|
|
||||||
should_do_colors_ = true;
|
template<typename ConsoleMutex>
|
||||||
break;
|
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color_mode_impl(color_mode mode)
|
||||||
case color_mode::never:
|
{
|
||||||
should_do_colors_ = false;
|
should_do_colors_ = mode != color_mode::never;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
should_do_colors_ = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set foreground color and return the orig console attributes (for resetting later)
|
// set foreground color and return the orig console attributes (for resetting later)
|
||||||
|
@ -55,6 +55,8 @@ protected:
|
|||||||
|
|
||||||
// in case we are redirected to file (not in console mode)
|
// in case we are redirected to file (not in console mode)
|
||||||
void write_to_file_(const memory_buf_t &formatted);
|
void write_to_file_(const memory_buf_t &formatted);
|
||||||
|
|
||||||
|
void set_color_mode_impl(color_mode mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ConsoleMutex>
|
template<typename ConsoleMutex>
|
||||||
|
Loading…
Reference in New Issue
Block a user