Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-03 08:52:58

0001 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
0002 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
0003 
0004 #pragma once
0005 
0006 #include <spdlog/common.h>
0007 #include <tuple>
0008 
0009 namespace spdlog {
0010 namespace details {
0011 
0012 // Helper class for file sinks.
0013 // When failing to open a file, retry several times(5) with a delay interval(10 ms).
0014 // Throw spdlog_ex exception on errors.
0015 
0016 class SPDLOG_API file_helper {
0017 public:
0018     file_helper() = default;
0019     explicit file_helper(const file_event_handlers &event_handlers);
0020 
0021     file_helper(const file_helper &) = delete;
0022     file_helper &operator=(const file_helper &) = delete;
0023     ~file_helper();
0024 
0025     void open(const filename_t &fname, bool truncate = false);
0026     void reopen(bool truncate);
0027     void flush();
0028     void sync();
0029     void close();
0030     void write(const memory_buf_t &buf);
0031     size_t size() const;
0032     const filename_t &filename() const;
0033 
0034     //
0035     // return file path and its extension:
0036     //
0037     // "mylog.txt" => ("mylog", ".txt")
0038     // "mylog" => ("mylog", "")
0039     // "mylog." => ("mylog.", "")
0040     // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
0041     //
0042     // the starting dot in filenames is ignored (hidden files):
0043     //
0044     // ".mylog" => (".mylog". "")
0045     // "my_folder/.mylog" => ("my_folder/.mylog", "")
0046     // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
0047     static std::tuple<filename_t, filename_t> split_by_extension(const filename_t &fname);
0048 
0049 private:
0050     const int open_tries_ = 5;
0051     const unsigned int open_interval_ = 10;
0052     std::FILE *fd_{nullptr};
0053     filename_t filename_;
0054     file_event_handlers event_handlers_;
0055 };
0056 }  // namespace details
0057 }  // namespace spdlog
0058 
0059 #ifdef SPDLOG_HEADER_ONLY
0060     #include "file_helper-inl.h"
0061 #endif