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_();
70 if (msg.
time >= rotation_tp_)
72 file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(msg.
time)), truncate_);
73 rotation_tp_ = next_rotation_tp_();
77 file_helper_.write(formatted);
88 time_t tnow = log_clock::to_time_t(tp);
95 tm date = now_tm(
now);
96 date.tm_hour = rotation_h_;
97 date.tm_min = rotation_m_;
99 auto rotation_time = log_clock::from_time_t(std::mktime(&date));
100 if (rotation_time >
now)
102 return rotation_time;
104 return {rotation_time + std::chrono::hours(24)};
123 template<
typename Factory = default_factory>
127 return Factory::template create<sinks::daily_file_sink_mt>(logger_name,
filename, hour, minute, truncate);
130 template<
typename Factory = default_factory>
134 return Factory::template create<sinks::daily_file_sink_st>(logger_name,
filename, hour, minute, truncate);
log_clock::time_point rotation_tp_
void msg(const char *fmt,...)
std::unique_ptr< spdlog::formatter > formatter_
log_clock::time_point next_rotation_tp_()
static filename_t calc_filename(const filename_t &filename, const tm &now_tm)
tm now_tm(log_clock::time_point tp)
std::enable_if< is_contiguous< Container >::value &&internal::is_string< S >::value, std::back_insert_iterator< Container > >::type format_to(std::back_insert_iterator< Container > out, const S &format_str, const Args &...args)
static std::tuple< filename_t, filename_t > split_by_extension(const spdlog::filename_t &fname)
details::file_helper file_helper_
filename_t base_filename_
std::shared_ptr< logger > daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour=0, int minute=0, bool truncate=false)
std::shared_ptr< logger > daily_logger_st(const std::string &logger_name, const filename_t &filename, int hour=0, int minute=0, bool truncate=false)
const GenericPointer< typename T::ValueType > T2 value
#define SPDLOG_FILENAME_T(s)
void sink_it_(const details::log_msg &msg) override
std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
std::string to_string(ModuleType const mt)
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate=false)
log_clock::time_point time