38 w,
SPDLOG_FILENAME_T(
"{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, ext);
46 template<
typename Mutex,
typename FileNameCalc = daily_filename_calculator>
52 : base_filename_(
std::move(base_filename))
53 , rotation_h_(rotation_hour)
54 , rotation_m_(rotation_minute)
57 if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
59 throw spdlog_ex(
"daily_file_sink: Invalid rotation time in ctor");
62 file_helper_.
open(FileNameCalc::calc_filename(base_filename_, now_tm(
now)), truncate_);
63 rotation_tp_ = next_rotation_tp_();
75 if (msg.
time >= rotation_tp_)
77 file_helper_.
open(FileNameCalc::calc_filename(base_filename_, now_tm(msg.
time)), truncate_);
78 rotation_tp_ = next_rotation_tp_();
82 file_helper_.
write(formatted);
91 tm now_tm(log_clock::time_point tp)
93 time_t tnow = log_clock::to_time_t(tp);
97 log_clock::time_point next_rotation_tp_()
100 tm date = now_tm(
now);
101 date.tm_hour = rotation_h_;
102 date.tm_min = rotation_m_;
104 auto rotation_time = log_clock::from_time_t(std::mktime(&date));
105 if (rotation_time >
now)
107 return rotation_time;
109 return {rotation_time + std::chrono::hours(24)};
115 log_clock::time_point rotation_tp_;
116 details::file_helper file_helper_;
128 template<
typename Factory = default_factory>
130 const std::string &logger_name,
const filename_t &filename,
int hour = 0,
int minute = 0,
bool truncate =
false)
132 return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute, truncate);
135 template<
typename Factory = default_factory>
137 const std::string &logger_name,
const filename_t &filename,
int hour = 0,
int minute = 0,
bool truncate =
false)
139 return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute, truncate);