qxLib
fwrite_logger_stream.inl
Go to the documentation of this file.
1 /**
2 
3  @file fwrite_logger_stream.inl
4  @author Khrapov
5  @date 18.01.2026
6  @copyright © Nick Khrapov, 2026. All right reserved.
7 
8 **/
9 
10 namespace qx
11 {
12 
13 inline fwrite_logger_stream::fwrite_logger_stream(const config& streamConfig) noexcept
14  : base_standard_streams_stream(streamConfig)
15 {
16 }
17 
19 {
20  fflush(stdout);
21  fflush(stderr);
22 }
23 
24 inline void fwrite_logger_stream::cout_colorized(verbosity eVerbosity, string_view svMessage, const color& rangeColor)
25 {
26  check_previous_message(eVerbosity);
27 
28  FILE* output = !is_error(eVerbosity) ? stdout : stderr;
29  terminal_color::font(rangeColor).write(output);
30  fwrite(svMessage.data(), sizeof(char_type), svMessage.size(), output);
31  terminal_color::reset().write(output);
32 }
33 
34 inline void fwrite_logger_stream::cout_common(verbosity eVerbosity, string_view svMessage)
35 {
36  check_previous_message(eVerbosity);
37 
38  FILE* output = !is_error(eVerbosity) ? stdout : stderr;
39  fwrite(svMessage.data(), sizeof(char_type), svMessage.size(), output);
40 }
41 
42 } // namespace qx
A base class for logger streams based on standard streams.
void check_previous_message(verbosity eCurrentMessageVerbosity)
Check the previous message type and flush if needed.
RGBA color.
Definition: color.h:193
virtual void do_flush() override
Flush the stream.
fwrite_logger_stream(const config &streamConfig=config()) noexcept
fwrite_logger_stream object constructor
static constexpr terminal_color reset() noexcept
Reset all colors.
void write(FILE *pStream) const
Write terminal color to the specified stream.
static constexpr terminal_color font(const color &fontColor) noexcept
Set font color.
bool is_error(verbosity eVerbosity) noexcept
Check if the verbosity level is an error.
Definition: verbosity.h:35