34 _file_helper.open(filename, truncate);
39 _force_flush = force_flush;
45 _file_helper.write(msg);
69 std::size_t max_size, std::size_t max_files) :
70 _base_filename(base_filename),
72 _max_files(max_files),
76 _file_helper.open(calc_filename(_base_filename, 0));
77 _current_size = _file_helper.size();
85 if (_current_size > _max_size)
90 _file_helper.write(msg);
118 _file_helper.close();
119 for (
auto i = _max_files; i > 0; --i)
121 filename_t src = calc_filename(_base_filename, i - 1);
136 _file_helper.reopen(
true);
158 w.
write(
SPDLOG_FILENAME_T(
"{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
173 w.
write(
SPDLOG_FILENAME_T(
"{}_{:04d}-{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
181 template<
class Mutex,
class FileNameCalc = default_daily_file_name_calculator>
182 class daily_file_sink SPDLOG_FINAL :
public base_sink < Mutex >
189 int rotation_minute) : _base_filename(base_filename),
190 _rotation_h(rotation_hour),
191 _rotation_m(rotation_minute)
193 if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
194 throw spdlog_ex(
"daily_file_sink: Invalid rotation time in ctor");
195 _rotation_tp = _next_rotation_tp();
196 _file_helper.open(FileNameCalc::calc_filename(_base_filename));
205 _file_helper.open(FileNameCalc::calc_filename(_base_filename));
206 _rotation_tp = _next_rotation_tp();
208 _file_helper.write(msg);
213 _file_helper.flush();
220 time_t tnow = std::chrono::system_clock::to_time_t(
now);
222 date.tm_hour = _rotation_h;
223 date.tm_min = _rotation_m;
225 auto rotation_time = std::chrono::system_clock::from_time_t(std::mktime(&date));
226 if (rotation_time >
now)
227 return rotation_time;
229 return std::chrono::system_clock::time_point(rotation_time + std::chrono::hours(24));
daily_file_sink< std::mutex > daily_file_sink_mt
details::file_helper _file_helper
int rename(const filename_t &filename1, const filename_t &filename2)
int remove(const filename_t &filename)
void write(BasicCStringRef< Char > format, ArgList args)
std::size_t _current_size
spdlog::log_clock::time_point now()
static bool file_exists(const filename_t &name)
filename_t _base_filename
static filename_t calc_filename(const filename_t &basename)
BasicMemoryWriter< char > MemoryWriter
rotating_file_sink(const filename_t &base_filename, std::size_t max_size, std::size_t max_files)
std::chrono::system_clock::time_point _rotation_tp
std::tm localtime(const std::time_t &time_tt)
rotating_file_sink< std::mutex > rotating_file_sink_mt
static filename_t calc_filename(const filename_t &basename)
simple_file_sink(const filename_t &filename, bool truncate=false)
fmt::MemoryWriter formatted
rotating_file_sink< details::null_mutex > rotating_file_sink_st
void _sink_it(const details::log_msg &msg) override
std::chrono::system_clock::time_point _next_rotation_tp()
daily_file_sink(const filename_t &base_filename, int rotation_hour, int rotation_minute)
#define SPDLOG_FILENAME_T(s)
static filename_t calc_filename(const filename_t &filename, std::size_t index)
daily_file_sink< details::null_mutex > daily_file_sink_st
void set_force_flush(bool force_flush)
std::string filename_to_str(const filename_t &filename)
simple_file_sink< std::mutex > simple_file_sink_mt
simple_file_sink< details::null_mutex > simple_file_sink_st