|
|
@ -25,6 +25,7 @@ class wincolor_sink : public base_sink<Mutex>
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
const WORD BOLD = FOREGROUND_INTENSITY;
|
|
|
|
const WORD BOLD = FOREGROUND_INTENSITY;
|
|
|
|
const WORD RED = FOREGROUND_RED;
|
|
|
|
const WORD RED = FOREGROUND_RED;
|
|
|
|
|
|
|
|
const WORD GREEN = FOREGROUND_GREEN;
|
|
|
|
const WORD CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
const WORD CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN;
|
|
|
|
const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN;
|
|
|
@ -32,9 +33,9 @@ public:
|
|
|
|
wincolor_sink(HANDLE std_handle)
|
|
|
|
wincolor_sink(HANDLE std_handle)
|
|
|
|
: out_handle_(std_handle)
|
|
|
|
: out_handle_(std_handle)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
colors_[level::trace] = CYAN;
|
|
|
|
colors_[level::trace] = WHITE;
|
|
|
|
colors_[level::debug] = CYAN;
|
|
|
|
colors_[level::debug] = CYAN;
|
|
|
|
colors_[level::info] = WHITE | BOLD;
|
|
|
|
colors_[level::info] = GREEN;
|
|
|
|
colors_[level::warn] = YELLOW | BOLD;
|
|
|
|
colors_[level::warn] = YELLOW | BOLD;
|
|
|
|
colors_[level::err] = RED | BOLD; // red bold
|
|
|
|
colors_[level::err] = RED | BOLD; // red bold
|
|
|
|
colors_[level::critical] = BACKGROUND_RED | WHITE | BOLD; // white bold on red background
|
|
|
|
colors_[level::critical] = BACKGROUND_RED | WHITE | BOLD; // white bold on red background
|
|
|
@ -59,10 +60,22 @@ public:
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
void _sink_it(const details::log_msg &msg) override
|
|
|
|
void _sink_it(const details::log_msg &msg) override
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto color = colors_[msg.level];
|
|
|
|
if (msg.color_range_end > msg.color_range_start)
|
|
|
|
auto orig_attribs = set_console_attribs(color);
|
|
|
|
{
|
|
|
|
WriteConsoleA(out_handle_, msg.formatted.data(), static_cast<DWORD>(msg.formatted.size()), nullptr, nullptr);
|
|
|
|
// before color range
|
|
|
|
SetConsoleTextAttribute(out_handle_, orig_attribs); // reset to orig colors
|
|
|
|
_print_range(msg, 0, msg.color_range_start);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// in color range
|
|
|
|
|
|
|
|
auto orig_attribs = set_console_attribs(colors_[msg.level]);
|
|
|
|
|
|
|
|
_print_range(msg, msg.color_range_start, msg.color_range_end);
|
|
|
|
|
|
|
|
::SetConsoleTextAttribute(out_handle_, orig_attribs); // reset to orig colors
|
|
|
|
|
|
|
|
// after color range
|
|
|
|
|
|
|
|
_print_range(msg, msg.color_range_end, msg.formatted.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else // print without colors if color range is invalid
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_print_range(msg, 0, msg.formatted.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _flush() override
|
|
|
|
void _flush() override
|
|
|
@ -86,6 +99,13 @@ private:
|
|
|
|
SetConsoleTextAttribute(out_handle_, attribs | back_color);
|
|
|
|
SetConsoleTextAttribute(out_handle_, attribs | back_color);
|
|
|
|
return orig_buffer_info.wAttributes; // return orig attribs
|
|
|
|
return orig_buffer_info.wAttributes; // return orig attribs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// print a range of formatted message to console
|
|
|
|
|
|
|
|
void _print_range(const details::log_msg &msg, size_t start, size_t end)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DWORD size = static_cast<DWORD>(end - start);
|
|
|
|
|
|
|
|
WriteConsoleA(out_handle_, msg.formatted.data() + start, size, nullptr, nullptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|