|
|
|
@ -46,11 +46,11 @@ struct minute_filename_calculator
|
|
|
|
|
* If max_files > 0, retain only the last max_files and delete previous.
|
|
|
|
|
*/
|
|
|
|
|
template<typename Mutex, typename FileNameCalc = minute_filename_calculator>
|
|
|
|
|
class minute_file_sink final : public base_sink<Mutex>
|
|
|
|
|
class minute_interval_file_sink final : public base_sink<Mutex>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// create every minute file sink which rotates on given time
|
|
|
|
|
minute_file_sink(
|
|
|
|
|
minute_interval_file_sink(
|
|
|
|
|
filename_t base_filename, bool truncate = false, uint16_t max_files = 0,
|
|
|
|
|
int rotation_minute = 0, const file_event_handlers &event_handlers = {})
|
|
|
|
|
: base_filename_(std::move(base_filename))
|
|
|
|
@ -61,10 +61,7 @@ public:
|
|
|
|
|
, filenames_q_()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (rotation_minute < 0 || rotation_minute > 59)
|
|
|
|
|
{
|
|
|
|
|
throw_spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto now = log_clock::now();
|
|
|
|
|
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
|
|
|
|
@ -193,8 +190,8 @@ private:
|
|
|
|
|
bool remove_init_file_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using minute_file_sink_mt = minute_file_sink<std::mutex>;
|
|
|
|
|
using minute_file_sink_st = minute_file_sink<details::null_mutex>;
|
|
|
|
|
using minute_interval_file_sink_mt = minute_interval_file_sink<std::mutex>;
|
|
|
|
|
using minute_interval_file_sink_st = minute_interval_file_sink<details::null_mutex>;
|
|
|
|
|
|
|
|
|
|
} // namespace sinks
|
|
|
|
|
|
|
|
|
@ -202,16 +199,16 @@ using minute_file_sink_st = minute_file_sink<details::null_mutex>;
|
|
|
|
|
// factory functions
|
|
|
|
|
//
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
|
inline std::shared_ptr<logger> minute_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
|
|
|
|
inline std::shared_ptr<logger> minute_interval_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
|
|
|
|
uint16_t max_files = 0, int minute = 0, const file_event_handlers &event_handlers = {})
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::minute_file_sink_mt>(logger_name, filename, truncate, max_files, minute ,event_handlers);
|
|
|
|
|
return Factory::template create<sinks::minute_interval_file_sink_mt>(logger_name, filename, truncate, max_files, minute ,event_handlers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
|
inline std::shared_ptr<logger> minute_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
|
|
|
|
inline std::shared_ptr<logger> minute_interval_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
|
|
|
|
uint16_t max_files = 0,int minute = 0, const file_event_handlers &event_handlers = {})
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::minute_file_sink_st>(logger_name, filename, truncate, max_files, minute, event_handlers);
|
|
|
|
|
return Factory::template create<sinks::minute_interval_file_sink_st>(logger_name, filename, truncate, max_files, minute, event_handlers);
|
|
|
|
|
}
|
|
|
|
|
} // namespace spdlog
|
|
|
|
|