qxLib
file_logger_stream_ofstream.h
Go to the documentation of this file.
1 /**
2 
3  @file file_logger_stream_ofstream.h
4  @author Khrapov
5  @date 14.01.2026
6  @copyright © Nick Khrapov, 2026. All right reserved.
7 
8 **/
9 #pragma once
10 
12 #include <qx/math/units/data.h>
13 
14 #include <fstream>
15 
16 namespace qx
17 {
18 
19 /**
20 
21  @class file_logger_stream_ofstream
22  @brief std::ofstream based file logger stream
23  @details UTF-8 LE (char) or UTF-16 LE (wchar_t)
24  @author Khrapov
25  @date 14.01.2026
26 
27 **/
29 {
30 public:
31  /**
32  @brief file_logger_stream_ofstream object constructor
33  @param streamConfig - file logger configuration
34  @param bufferSize - Outer buffer size for a FILE. if 0, the default buffer is used
35  The buffer size determines how often data will be flushed.
36  The default value of 8192 chars corresponds to ~30-50 lines of logs.
37  **/
39  const config& streamConfig = config(),
40  unit<size_t, units::data> bufferSize = { 8192 * sizeof(char_type), units::data::bytes }) noexcept;
42 
43  virtual ~file_logger_stream_ofstream() override;
44 
45  // base_logger_stream
46  //
47  virtual void do_log(const category& category, verbosity eVerbosity, string_view svMessage) override;
48  virtual void do_flush() override;
49 
50 private:
51  std::basic_ofstream<char_type> m_File;
52  std::vector<char_type> m_Buffer;
53 };
54 
55 } // namespace qx
56 
Base class for all file logger streams.
A category is a class that identifies a particular piece of code. This code can be located in differe...
Definition: category.h:59
std::ofstream based file logger stream
virtual void do_log(const category &category, verbosity eVerbosity, string_view svMessage) override
Proceed stream logging.
file_logger_stream_ofstream(const config &streamConfig=config(), unit< size_t, units::data > bufferSize={ 8192 *sizeof(char_type), units::data::bytes }) noexcept
file_logger_stream_ofstream object constructor
virtual void do_flush() override
Flush the stream.
Definition: base.h:52