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 {
28 
29 public:
31  {
32  // Is it necessary to insert colour tags to highlight certain parts of messages?
33  // For example, each category has its own colour.
34  // Consoles can understand these tags, but they may be unnecessary when outputting to another location.
35  bool bUseColors = false;
36 
37  // Should the order of normal messages and errors be synchronised?
38  // These two types of messages go to different standard streams, and in general,
39  // preserving the order is not guaranteed.
40  // This option flushes the stream if the previous message was of a different type.
41  bool bSyncUsualAndErrorMessages = true;
42  };
43 
44 public:
45  /**
46  @brief base_standard_streams_stream object constructor
47  @param streamConfig - logger stream configuration
48  **/
49  base_standard_streams_stream(const config& streamConfig) noexcept;
50 
52 
53  // base_logger_stream
54  //
55  virtual void do_log(
56  const category& category,
57  verbosity eVerbosity,
58  std::thread::id threadId,
59  std::chrono::system_clock::time_point messageTime,
60  string_view svFile,
61  string_view svFunction,
62  int nLine,
63  string_view svMessage) override;
64 
65 protected:
66  /**
67  @brief Check the previous message type and flush if needed
68  @param eCurrentMessageVerbosity - current message verbosity
69  **/
70  void check_previous_message(verbosity eCurrentMessageVerbosity);
71 
72 private:
73  /**
74  @brief Output colorized message to standard streams
75  @param eVerbosity - message verbosity
76  @param svMessage - message text
77  @param rangeColor - a terminal color for the message
78  **/
79  virtual void cout_colorized(verbosity eVerbosity, string_view svMessage, const color& rangeColor) = 0;
80 
81  /**
82  @brief Output a message with a default color
83  @param eVerbosity - message verbosity
84  @param svMessage - message text
85  **/
86  virtual void cout_common(verbosity eVerbosity, string_view svMessage) = 0;
87 
88 private:
89  bool m_bUsingColors = false;
90  bool m_bSyncUsualAndErrorMessages = true;
91  bool m_bPrevMessageWasError = false;
92 };
93 
94 } // namespace qx
95 
96 #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, std::thread::id threadId, std::chrono::system_clock::time_point messageTime, string_view svFile, string_view svFunction, int nLine, 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