36 return fmt_lib::format(
SPDLOG_FILENAME_T(
"{}_{:04d}-{:02d}-{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
37 now_tm.tm_mday, now_tm.tm_hour, ext);
46 template <
typename Mutex,
typename FileNameCalc = hourly_filename_calculator>
55 auto now = log_clock::now();
112 std::vector<filename_t> filenames;
113 auto now = log_clock::now();
122 now -= std::chrono::hours(1);
124 for (
auto iter = filenames.rbegin(); iter != filenames.rend(); ++iter)
132 time_t tnow = log_clock::to_time_t(tp);
138 auto now = log_clock::now();
142 auto rotation_time = log_clock::from_time_t(std::mktime(&date));
143 if (rotation_time > now)
145 return rotation_time;
147 return {rotation_time + std::chrono::hours(1)};
162 bool ok = remove_if_exists(old_filename) == 0;
189 template <
typename Factory = spdlog::synchronous_factory>
192 return Factory::template create<sinks::hourly_file_sink_mt>(logger_name, filename, truncate, max_files, event_handlers);
195 template <
typename Factory = spdlog::synchronous_factory>
198 return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate, max_files, event_handlers);
Definition circular_q.h:16
void pop_front()
Definition circular_q.h:103
const T & front() const
Definition circular_q.h:70
void push_back(T &&item)
Definition circular_q.h:53
bool full() const
Definition circular_q.h:113
Definition file_helper.h:19
const filename_t & filename() const
Definition file_helper-inl.h:142
size_t size() const
Definition file_helper-inl.h:133
void flush()
Definition file_helper-inl.h:88
void write(const memory_buf_t &buf)
Definition file_helper-inl.h:123
static std::tuple< filename_t, filename_t > split_by_extension(const filename_t &fname)
Definition file_helper-inl.h:160
void close()
Definition file_helper-inl.h:104
void open(const filename_t &fname, bool truncate=false)
Definition file_helper-inl.h:35
Definition base_sink.h:22
Definition hourly_file_sink.h:48
hourly_file_sink(filename_t base_filename, bool truncate=false, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition hourly_file_sink.h:51
log_clock::time_point rotation_tp_
Definition hourly_file_sink.h:173
tm now_tm(log_clock::time_point tp)
Definition hourly_file_sink.h:130
bool remove_init_file_
Definition hourly_file_sink.h:178
details::circular_q< filename_t > filenames_q_
Definition hourly_file_sink.h:177
filename_t filename()
Definition hourly_file_sink.h:67
void flush_() override
Definition hourly_file_sink.h:101
void delete_old_()
Definition hourly_file_sink.h:152
void init_filenames_q_()
Definition hourly_file_sink.h:107
details::file_helper file_helper_
Definition hourly_file_sink.h:174
filename_t base_filename_
Definition hourly_file_sink.h:172
log_clock::time_point next_rotation_tp_()
Definition hourly_file_sink.h:136
void sink_it_(const details::log_msg &msg) override
Definition hourly_file_sink.h:74
uint16_t max_files_
Definition hourly_file_sink.h:176
bool truncate_
Definition hourly_file_sink.h:175
#define SPDLOG_FILENAME_T(s)
Definition common.h:132
#define SPDLOG_THROW(ex)
Definition common.h:108
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
Definition os-inl.h:399
SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:177
SPDLOG_INLINE int remove(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:168
SPDLOG_INLINE std::tm localtime() SPDLOG_NOEXCEPT
Definition os-inl.h:102
SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:192
hourly_file_sink< details::null_mutex > hourly_file_sink_st
Definition hourly_file_sink.h:182
hourly_file_sink< std::mutex > hourly_file_sink_mt
Definition hourly_file_sink.h:181
std::string filename_t
Definition common.h:131
std::shared_ptr< logger > hourly_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate=false, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition hourly_file_sink.h:196
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:173
std::shared_ptr< logger > hourly_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate=false, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition hourly_file_sink.h:190
log_clock::time_point time
Definition log_msg.h:24
Definition hourly_file_sink.h:30
static filename_t calc_filename(const filename_t &filename, const tm &now_tm)
Definition hourly_file_sink.h:32
time
Definition tag_strings.h:53