36 SPDLOG_FILENAME_T(
"{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, ext);
53#if defined(_MSC_VER) && defined(SPDLOG_WCHAR_FILENAMES)
54 return fmt::format(fmt_filename, now_tm);
66template<
typename Mutex,
typename FileNameCalc = daily_filename_calculator>
79 if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
104 auto time = msg.
time;
146 for (
auto iter = filenames.
rbegin(); iter != filenames.
rend(); ++iter)
166 if (rotation_time > now)
168 return rotation_time;
185 bool ok = remove_if_exists(old_filename) == 0;
189 throw_spdlog_ex(
"Failed removing daily file " + filename_to_str(old_filename), errno);
215template<
typename Factory = spdlog::synchronous_factory>
217 const std::string &logger_name,
const filename_t &filename,
int hour = 0,
int minute = 0,
bool truncate =
false, uint16_t max_files = 0)
219 return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute, truncate, max_files);
222template<
typename Factory = spdlog::synchronous_factory>
224 const std::string &logger_name,
const filename_t &filename,
int hour = 0,
int minute = 0,
bool truncate =
false, uint16_t max_files = 0)
226 return Factory::template create<sinks::daily_file_format_sink_mt>(logger_name, filename, hour, minute, truncate, max_files);
229template<
typename Factory = spdlog::synchronous_factory>
231 const std::string &logger_name,
const filename_t &filename,
int hour = 0,
int minute = 0,
bool truncate =
false, uint16_t max_files = 0)
233 return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute, truncate, max_files);
236template<
typename Factory = spdlog::synchronous_factory>
238 const std::string &logger_name,
const filename_t &filename,
int hour = 0,
int minute = 0,
bool truncate =
false, uint16_t max_files = 0)
240 return Factory::template create<sinks::daily_file_format_sink_st>(logger_name, filename, hour, minute, truncate, max_files);
const filename_t & filename() const
void write(const memory_buf_t &buf)
static std::tuple< filename_t, filename_t > split_by_extension(const filename_t &fname)
void open(const filename_t &fname, bool truncate=false)
log_clock::time_point rotation_tp_
log_clock::time_point next_rotation_tp_()
details::circular_q< filename_t > filenames_q_
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate=false, uint16_t max_files=0)
tm now_tm(log_clock::time_point tp)
void sink_it_(const details::log_msg &msg) override
details::file_helper file_helper_
filename_t base_filename_
#define SPDLOG_FILENAME_T(s)
#define SPDLOG_FMT_RUNTIME(format_string)
T emplace_back(T... args)
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT
SPDLOG_INLINE std::tm localtime() SPDLOG_NOEXCEPT
SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT
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)
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)
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)
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno)
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)
fmt::basic_memory_buffer< char, 250 > memory_buf_t
log_clock::time_point time
static filename_t calc_filename(const filename_t &filename, const tm &now_tm)