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