qxLib
base_standard_streams_stream.h
Go to the documentation of this file.
1 /**
2 
3  @file base_standard_streams_stream.h
4  @author Khrapov
5  @date 18.01.2026
6  @copyright © Nick Khrapov, 2026. All right reserved.
7 
8 **/
9 #pragma once
10 
13 
14 namespace qx
15 {
16 
17 /**
18 
19  @class base_standard_streams_stream
20  @brief A base class for logger streams based on standard streams
21  @author Khrapov
22  @date 18.01.2026
23 
24 **/
26 {
27 public:
29  {
30  // Is it necessary to insert colour tags to highlight certain parts of messages?
31  // For example, each category has its own colour.
32  // Consoles can understand these tags, but they may be unnecessary when outputting to another location.
33  bool bUseColors = false;
34 
35  //Should the order of normal messages and errors be synchronised?
36  //These two types of messages go to different standard streams, and in general,
37  //preserving the order is not guaranteed.
38  //This option flushes the stream if the previous message was of a different type.
39  bool bSyncUsualAndErrorMessages = true;
40  };
41 
42 public:
43  /**
44  @brief base_standard_streams_stream object constructor
45  @param streamConfig - logger stream configuration
46  **/
47  base_standard_streams_stream(const config& streamConfig) noexcept;
48 
50 
51  // base_logger_stream
52  //
53  virtual void do_log(const category& category, verbosity eVerbosity, string_view svMessage) override;
54 
55 protected:
56  /**
57  @brief Check the previous message type and flush if needed
58  @param eCurrentMessageVerbosity - current message verbosity
59  **/
60  void check_previous_message(verbosity eCurrentMessageVerbosity);
61 
62 private:
63  /**
64  @brief Output colorized message to standard streams
65  @param eVerbosity - message verbosity
66  @param svMessage - message text
67  @param rangeColor - a terminal color for the message
68  **/
69  virtual void cout_colorized(verbosity eVerbosity, string_view svMessage, const color& rangeColor) = 0;
70 
71  /**
72  @brief Output a message with a default color
73  @param eVerbosity - message verbosity
74  @param svMessage - message text
75  **/
76  virtual void cout_common(verbosity eVerbosity, string_view svMessage) = 0;
77 
78 private:
79  bool m_bUsingColors = false;
80  bool m_bSyncUsualAndErrorMessages = true;
81  bool m_bPrevMessageWasError = false;
82 };
83 
84 } // namespace qx
85 
86 #include <qx/logger/base_standard_streams_stream.inl>
Base class for logger streams.
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.
base_standard_streams_stream(const config &streamConfig) noexcept
base_standard_streams_stream object constructor
virtual void do_log(const category &category, verbosity eVerbosity, string_view svMessage) override
Proceed stream logging.
A category is a class that identifies a particular piece of code. This code can be located in differe...
Definition: category.h:59
RGBA color.
Definition: color.h:193