16 bool bDisableStdioSync,
19 , m_bUsingColors(bUseColors)
21 if (bDisableStdioSync)
25 std::ios_base::sync_with_stdio(
false);
33 std::wcin.tie(
nullptr);
34 std::wcout.tie(
nullptr);
40 QX_PERF_SCOPE(CatLogger,
"Flush to cout");
42 std::wcout << std::flush;
46 string_view svMessage,
48 const std::vector<logger_color_range>& colors,
51 QX_PERF_SCOPE(CatLogger,
"Log to cout");
53 thread_local
wstring sWideMessage;
58 color commonColor = color::white();
61 case verbosity::very_verbose:
62 case verbosity::verbose:
63 commonColor = color::gray();
67 commonColor = color::white();
70 case verbosity::important:
71 commonColor = color::khaki();
74 case verbosity::warning:
75 commonColor = color::orange();
78 case verbosity::error:
79 commonColor = color::crimson();
82 case verbosity::critical:
83 commonColor = color::dark_red();
87 auto cout_colorized = [](
size_t nStart,
size_t nEnd,
const color& rangeColor)
93 cout_colorized(0, colors.empty() ? sWideMessage.size() : colors.front().range.first, commonColor);
95 for (
size_t i = 0; i < colors.size(); ++i)
97 cout_colorized(colors[i].range.first, colors[i].range.second, colors[i].rangeColor);
99 colors[i].range.second,
100 i + 1 < colors.size() ? colors[i + 1].range.first : sWideMessage.size(),
106 std::wcout << sWideMessage;
112 m_bUsingColors = bUsingColors;
Base class for logger streams.
virtual void flush() override
Flush stream.
cout_logger_stream(bool bAlwaysFlush=false, bool bUseColors=true, bool bDisableStdioSync=true, bool bUntieCin=true)
cout_logger_stream object constructor
virtual void do_log(string_view svMessage, const log_unit &logUnit, const std::vector< logger_color_range > &colors, verbosity eVerbosity) override
Proceed stream logging.
void set_using_colors(bool bUsingColors) noexcept
Set whether cout output should be colored.
static constexpr terminal_color reset() noexcept
Reset all colors.
static constexpr terminal_color font(const color &fontColor) noexcept
Set font color.
wstring to_wstring(cstring_view stringView, const std::locale &locale=std::locale())
convert cstring to wstring