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_();
68 return file_helper_.filename();
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_;
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);
spdlog::log_clock::time_point now() noexcept
std::unique_ptr< spdlog::formatter > formatter_
std::tm localtime(const std::time_t &time_tt) noexcept
static filename_t calc_filename(const filename_t &filename, const tm &now_tm)
static std::tuple< filename_t, filename_t > split_by_extension(const spdlog::filename_t &fname)
basic_memory_buffer< char > memory_buffer
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)
const filename_t & filename() const
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)
#define SPDLOG_FILENAME_T(s)
void sink_it_(const details::log_msg &msg) override
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)
std::string to_string(const T &value)
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate=false)
log_clock::time_point time