qxLib
base_file_logger_stream.h
Go to the documentation of this file.
1 /**
2 
3  @file base_file_logger_stream.h
4  @author Khrapov
5  @date 28.07.2021
6  @copyright (c) Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
12 
13 #include <filesystem>
14 
15 namespace qx
16 {
17 
18 enum class log_file_policy
19 {
20  append, //!< append all
21  clear_then_upend, //!< clear file at start, then append
22  time_name, //!< create new file with creation time name
23  time_name_keep_current, //!< the current file name: svFilePrefix, old ones: svFilePrefix_last_modification_time
24 };
25 
26 /**
27 
28  @class base_file_logger_stream
29  @brief Base class for all file logger streams
30  @author Khrapov
31  @date 28.07.2021
32 
33 **/
35 {
37 
38 public:
40  {
41  log_file_policy eLogFilePolicy = log_file_policy::append;
42  size_t nMaxLogFiles = 0; // number of log files to keep if using time_name policy (logs rotation)
43  string_view svLogsDirectory = QXT("./"); // current working directory
44  string_view svFilePrefix = QXT("qx_app");
45  string_view svFileExtension = QXT(".log");
46  };
47 
48 public:
49  /**
50  @brief file_logger_stream object constructor
51  @param streamConfig - file logger configuration
52  **/
53  base_file_logger_stream(const config& streamConfig) noexcept;
55 
56 protected:
57  /**
58  @brief Create a folder (if required) and get log file path
59  @param config - file logger configuration
60  @retval - log file path, empty path on error
61  **/
62  std::filesystem::path prepare_folder_and_get_log_file_path(const config& config) noexcept;
63 };
64 
65 } // namespace qx
66 
67 #include <qx/logger/base_file_logger_stream.inl>
@ time_name_keep_current
the current file name: svFilePrefix, old ones: svFilePrefix_last_modification_time
@ clear_then_upend
clear file at start, then append
@ time_name
create new file with creation time name
@ append
append all
Base class for all file logger streams.
base_file_logger_stream(const config &streamConfig) noexcept
file_logger_stream object constructor
std::filesystem::path prepare_folder_and_get_log_file_path(const config &config) noexcept
Create a folder (if required) and get log file path.
Base class for logger streams.