Agora  1.2.0
Agora project
file_helper.h
Go to the documentation of this file.
1 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
3 
4 #pragma once
5 
6 #include <spdlog/common.h>
7 #include <tuple>
8 
9 namespace spdlog {
10 namespace details {
11 
12 // Helper class for file sinks.
13 // When failing to open a file, retry several times(5) with a delay interval(10 ms).
14 // Throw spdlog_ex exception on errors.
15 
17 {
18 public:
19  file_helper() = default;
20  explicit file_helper(const file_event_handlers &event_handlers);
21 
22  file_helper(const file_helper &) = delete;
23  file_helper &operator=(const file_helper &) = delete;
24  ~file_helper();
25 
26  void open(const filename_t &fname, bool truncate = false);
27  void reopen(bool truncate);
28  void flush();
29  void close();
30  void write(const memory_buf_t &buf);
31  size_t size() const;
32  const filename_t &filename() const;
33 
34  //
35  // return file path and its extension:
36  //
37  // "mylog.txt" => ("mylog", ".txt")
38  // "mylog" => ("mylog", "")
39  // "mylog." => ("mylog.", "")
40  // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
41  //
42  // the starting dot in filenames is ignored (hidden files):
43  //
44  // ".mylog" => (".mylog". "")
45  // "my_folder/.mylog" => ("my_folder/.mylog", "")
46  // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
47  static std::tuple<filename_t, filename_t> split_by_extension(const filename_t &fname);
48 
49 private:
50  const int open_tries_ = 5;
51  const unsigned int open_interval_ = 10;
52  std::FILE *fd_{nullptr};
55 };
56 } // namespace details
57 } // namespace spdlog
58 
59 #ifdef SPDLOG_HEADER_ONLY
60 # include "file_helper-inl.h"
61 #endif
spdlog::file_event_handlers
Definition: common.h:308
size
end IFFT Reshape the symbol vector into two different spatial streams size
Definition: generate_data.m:73
fmt::v8::detail::write
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
Definition: chrono.h:425
spdlog::details::file_helper
Definition: file_helper.h:16
matplotlibcpp::close
void close()
Definition: matplotlibcpp.h:2567
filename
filename
Definition: parse_all_dl.m:14
file_helper-inl.h
fmt::v8::basic_memory_buffer
Definition: format.h:677
spdlog
Definition: async.h:25
spdlog::details::file_helper::filename_
filename_t filename_
Definition: file_helper.h:53
common.h
spdlog::details::async_msg_type::flush
@ flush
spdlog::details::file_helper::event_handlers_
file_event_handlers event_handlers_
Definition: file_helper.h:54
spdlog::filename_t
std::string filename_t
Definition: common.h:122
SPDLOG_API
#define SPDLOG_API
Definition: common.h:40