6 #ifndef SPDLOG_HEADER_ONLY
18 template<
typename ConsoleMutex>
20 : out_handle_(out_handle)
21 , mutex_(ConsoleMutex::mutex())
33 BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
37 template<
typename ConsoleMutex>
44 template<
typename ConsoleMutex>
47 std::lock_guard<mutex_t> lock(mutex_);
48 colors_[level] =
color;
51 template<
typename ConsoleMutex>
54 if (out_handle_ ==
nullptr || out_handle_ == INVALID_HANDLE_VALUE)
59 std::lock_guard<mutex_t> lock(mutex_);
63 formatter_->format(msg, formatted);
69 auto orig_attribs =
static_cast<WORD
>(set_foreground_color_(colors_[msg.
level]));
72 ::SetConsoleTextAttribute(
static_cast<HANDLE
>(out_handle_), orig_attribs);
77 write_to_file_(formatted);
81 template<
typename ConsoleMutex>
87 template<
typename ConsoleMutex>
90 std::lock_guard<mutex_t> lock(mutex_);
94 template<
typename ConsoleMutex>
97 std::lock_guard<mutex_t> lock(mutex_);
98 formatter_ = std::move(sink_formatter);
101 template<
typename ConsoleMutex>
104 std::lock_guard<mutex_t> lock(mutex_);
105 set_color_mode_impl(
mode);
108 template<
typename ConsoleMutex>
115 bool in_console = ::GetConsoleMode(
static_cast<HANDLE
>(out_handle_), &console_mode) != 0;
116 should_do_colors_ = in_console;
125 template<
typename ConsoleMutex>
128 CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info;
129 if (!::GetConsoleScreenBufferInfo(
static_cast<HANDLE
>(out_handle_), &orig_buffer_info))
132 return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
136 auto new_attribs =
static_cast<WORD
>(attribs) | (orig_buffer_info.wAttributes & 0xfff0);
137 auto ignored = ::SetConsoleTextAttribute(
static_cast<HANDLE
>(out_handle_),
static_cast<WORD
>(new_attribs));
139 return static_cast<std::uint16_t
>(orig_buffer_info.wAttributes);
143 template<
typename ConsoleMutex>
149 auto ignored = ::WriteConsoleA(
static_cast<HANDLE
>(out_handle_), formatted.
data() +
start,
size,
nullptr,
nullptr);
154 template<
typename ConsoleMutex>
157 auto size =
static_cast<DWORD
>(formatted.
size());
158 DWORD bytes_written = 0;
159 auto ignored = ::WriteFile(
static_cast<HANDLE
>(out_handle_), formatted.
data(),
size, &bytes_written,
nullptr);
164 template<
typename ConsoleMutex>
170 template<
typename ConsoleMutex>