38 now_tm.tm_mon + 1, now_tm.tm_mday, ext);
53#ifdef SPDLOG_USE_STD_FORMAT
57 tm_format.append(filename);
61 tm_format.push_back(
' ');
63 const size_t MIN_SIZE = 10;
68 size_t count =
strftime(buf.data(), buf.size(), tm_format.c_str(), &now_tm);
72 buf.resize(
count - 1);
75 buf.resize(buf.size() * 2);
84#if defined(_MSC_VER) && defined(SPDLOG_WCHAR_FILENAMES) && FMT_VERSION < 90101
85 return fmt::format(fmt_filename, now_tm);
95#pragma GCC diagnostic push
96#pragma GCC diagnostic ignored "-Wformat-nonliteral"
110#pragma GCC diagnostic pop
119 template <
typename Mutex,
typename FileNameCalc = daily_filename_calculator>
127 if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
132 auto now = log_clock::now();
182 std::vector<filename_t> filenames;
183 auto now = log_clock::now();
192 now -= std::chrono::hours(24);
194 for (
auto iter = filenames.rbegin(); iter != filenames.rend(); ++iter)
202 time_t tnow = log_clock::to_time_t(tp);
208 auto now = log_clock::now();
213 auto rotation_time = log_clock::from_time_t(std::mktime(&date));
214 if (rotation_time > now)
216 return rotation_time;
218 return {rotation_time + std::chrono::hours(24)};
233 bool ok = remove_if_exists(old_filename) == 0;
237 throw_spdlog_ex(
"Failed removing daily file " + filename_to_str(old_filename), errno);
263 template <
typename Factory = spdlog::synchronous_factory>
264 inline 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, uint16_t max_files = 0,
const file_event_handlers& event_handlers = {})
266 return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute, truncate, max_files, event_handlers);
269 template <
typename Factory = spdlog::synchronous_factory>
272 return Factory::template create<sinks::daily_file_format_sink_mt>(
273 logger_name, filename, hour, minute, truncate, max_files, event_handlers);
276 template <
typename Factory = spdlog::synchronous_factory>
277 inline 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, uint16_t max_files = 0,
const file_event_handlers& event_handlers = {})
279 return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute, truncate, max_files, event_handlers);
282 template <
typename Factory = spdlog::synchronous_factory>
285 return Factory::template create<sinks::daily_file_format_sink_st>(
286 logger_name, filename, hour, minute, 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
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 open(const filename_t &fname, bool truncate=false)
Definition file_helper-inl.h:35
Definition base_sink.h:22
Definition daily_file_sink.h:121
void delete_old_()
Definition daily_file_sink.h:223
void init_filenames_q_()
Definition daily_file_sink.h:177
void flush_() override
Definition daily_file_sink.h:171
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate=false, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition daily_file_sink.h:124
bool truncate_
Definition daily_file_sink.h:248
uint16_t max_files_
Definition daily_file_sink.h:249
log_clock::time_point rotation_tp_
Definition daily_file_sink.h:246
log_clock::time_point next_rotation_tp_()
Definition daily_file_sink.h:206
details::circular_q< filename_t > filenames_q_
Definition daily_file_sink.h:250
int rotation_h_
Definition daily_file_sink.h:244
tm now_tm(log_clock::time_point tp)
Definition daily_file_sink.h:200
int rotation_m_
Definition daily_file_sink.h:245
void sink_it_(const details::log_msg &msg) override
Definition daily_file_sink.h:150
details::file_helper file_helper_
Definition daily_file_sink.h:247
filename_t filename()
Definition daily_file_sink.h:143
filename_t base_filename_
Definition daily_file_sink.h:243
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:646
#define SPDLOG_FMT_STRING(format_string)
Definition common.h:60
#define SPDLOG_FILENAME_T(s)
Definition common.h:132
#define SPDLOG_FMT_RUNTIME(format_string)
Definition common.h:59
constexpr auto count() -> size_t
Definition core.h:1538
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 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
daily_file_sink< details::null_mutex, daily_filename_format_calculator > daily_file_format_sink_st
Definition daily_file_sink.h:256
daily_file_sink< details::null_mutex > daily_file_sink_st
Definition daily_file_sink.h:254
daily_file_sink< std::mutex > daily_file_sink_mt
Definition daily_file_sink.h:253
daily_file_sink< std::mutex, daily_filename_format_calculator > daily_file_format_sink_mt
Definition daily_file_sink.h:255
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, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition daily_file_sink.h:277
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, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition daily_file_sink.h:264
std::shared_ptr< logger > daily_logger_format_mt(const std::string &logger_name, const filename_t &filename, int hour=0, int minute=0, bool truncate=false, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition daily_file_sink.h:270
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
Definition common-inl.h:75
std::string filename_t
Definition common.h:131
std::shared_ptr< logger > daily_logger_format_st(const std::string &logger_name, const filename_t &filename, int hour=0, int minute=0, bool truncate=false, uint16_t max_files=0, const file_event_handlers &event_handlers={})
Definition daily_file_sink.h:283
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:173
log_clock::time_point time
Definition log_msg.h:24
Definition daily_file_sink.h:31
static filename_t calc_filename(const filename_t &filename, const tm &now_tm)
Definition daily_file_sink.h:33
time
Definition tag_strings.h:53