qxLib
cout_logger_stream.h
Go to the documentation of this file.
1 /**
2 
3  @file cout_logger_stream.h
4  @author Khrapov
5  @date 28.07.2021
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
13 
14 #include <iostream>
15 
16 namespace qx
17 {
18 
19 /**
20 
21  @class cout_logger_stream
22  @brief Logger stream for std::cout output
23  @author Khrapov
24  @date 28.07.2021
25 
26 **/
28 {
29 public:
30  /**
31  @brief cout_logger_stream object constructor
32  @param bAlwaysFlush - true if need to flush after every output, decreases performance
33  @param bUseColors - use color when output is not info
34  @param bDisableStdioSync - don't synchronize to the standard C streams after each input/output operation
35  @param bUntieCin - untie cin from cout
36  **/
38  bool bAlwaysFlush = false,
39  bool bUseColors = true,
40  bool bDisableStdioSync = true,
41  bool bUntieCin = true);
42 
43  cout_logger_stream(cout_logger_stream&&) noexcept = default;
44 
45  // base_logger_stream
46  //
47  virtual void flush() override;
48  virtual void do_log(
49  string_view svMessage,
50  const log_unit& logUnit,
51  const std::vector<logger_color_range>& colors,
52  verbosity eVerbosity) override;
53 
54  /**
55  @brief Set whether cout output should be colored
56  @param bUsingColors - true if cout output should be colored
57  **/
58  void set_using_colors(bool bUsingColors) noexcept;
59 
60 private:
61  bool m_bUsingColors = true;
62 };
63 
64 } // namespace qx
65 
Base class for logger streams.
Logger stream for std::cout output.
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.