qxLib
base_file_logger_stream.inl
Go to the documentation of this file.
1 /**
2 
3  @file base_file_logger_stream.inl
4  @author Khrapov
5  @date 30.07.2021
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 
10 namespace qx
11 {
12 
13 inline base_file_logger_stream::base_file_logger_stream(const config& streamConfig) noexcept
14  : base_logger_stream(streamConfig)
15 {
16 }
17 
19  log_file_policy eLogFilePolicy,
20  string_view svFileName) noexcept
21 {
22  string sLogFile = svFileName;
23  if (eLogFilePolicy == log_file_policy::time_name)
24  {
25  string sTime;
26  append_time_string(sTime.begin(), QXT('-'), QXT('-'));
27 
28  size_t nInsetPos = sLogFile.rfind(QXT(".log"));
29  if (nInsetPos == string::npos)
30  nInsetPos = sLogFile.size();
31 
32  sLogFile.insert(nInsetPos, QXT('_'));
33  sLogFile.insert(nInsetPos + 1, sTime);
34  }
35 
36  std::filesystem::path path(sLogFile.c_str());
37  if (path.has_parent_path() && !std::filesystem::exists(path.parent_path()))
38  {
39  if (!std::filesystem::create_directory(path.parent_path()))
40  {
41  details::get_cerr<char_type>::get() << QXT("Can't create output folder ") << sLogFile;
42  return std::filesystem::path();
43  }
44  }
45 
46  return path;
47 }
48 
49 } // namespace qx
static std::filesystem::path create_folder_and_get_log_file_path(log_file_policy eLogFilePolicy, string_view svFileName) noexcept
Create a folder (if required) and get log file path.
base_file_logger_stream(const config &streamConfig) noexcept
file_logger_stream object constructor
Base class for logger streams.
size_type rfind(value_type chSymbol, size_type nBegin=npos, size_type nEnd=0) const noexcept
Find substring (reverse direction)
Definition: string.inl:1353
size_type insert(size_type nPos, value_type chSymbol) noexcept
Insert substring.
Definition: string.inl:424
const_pointer c_str() const noexcept
Get pointer to string zero terminated.
Definition: string.inl:244
void append_time_string(out_it_t it, char_type chDateDelimiter, char_type chTimeDelimiter) noexcept
Format time string to the buffer.
Definition: time_string.h:27