Photon 1.0.0
Loading...
Searching...
No Matches
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
9namespace spdlog
10{
11 namespace details
12 {
13
14 // Helper class for file sinks.
15 // When failing to open a file, retry several times(5) with a delay interval(10 ms).
16 // Throw spdlog_ex exception on errors.
17
19 {
20 public:
21 file_helper() = default;
22 explicit file_helper(const file_event_handlers& event_handlers);
23
24 file_helper(const file_helper&) = delete;
27
28 void open(const filename_t& fname, bool truncate = false);
29 void reopen(bool truncate);
30 void flush();
31 void sync();
32 void close();
33 void write(const memory_buf_t& buf);
34 size_t size() const;
35 const filename_t& filename() const;
36
37 //
38 // return file path and its extension:
39 //
40 // "mylog.txt" => ("mylog", ".txt")
41 // "mylog" => ("mylog", "")
42 // "mylog." => ("mylog.", "")
43 // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
44 //
45 // the starting dot in filenames is ignored (hidden files):
46 //
47 // ".mylog" => (".mylog". "")
48 // "my_folder/.mylog" => ("my_folder/.mylog", "")
49 // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
50 static std::tuple<filename_t, filename_t> split_by_extension(const filename_t& fname);
51
52 private:
53 const int open_tries_ = 5;
54 const unsigned int open_interval_ = 10;
55 std::FILE* fd_{nullptr};
58 };
59 } // namespace details
60} // namespace spdlog
61
62#ifdef SPDLOG_HEADER_ONLY
63#include "file_helper-inl.h"
64#endif
Definition file_helper.h:19
file_helper(const file_helper &)=delete
file_helper & operator=(const file_helper &)=delete
filename_t filename_
Definition file_helper.h:56
file_event_handlers event_handlers_
Definition file_helper.h:57
#define SPDLOG_API
Definition common.h:45
FMT_CONSTEXPR auto write(OutputIt out, Char value, const basic_format_specs< Char > &specs, locale_ref loc={}) -> OutputIt
Definition format.h:2272
Definition async.h:26
std::string filename_t
Definition common.h:131
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:173
Definition common.h:329
annotation details
Definition tag_strings.h:125