mirror of
https://github.com/gabime/spdlog.git
synced 2025-03-04 13:15:48 +08:00
Add files via upload
Change the logger name to reflect the minutes interval based rotation and remove the check for max min 59 in configuration.
This commit is contained in:
parent
9d8efbde23
commit
464013d958
@ -46,11 +46,11 @@ struct minute_filename_calculator
|
|||||||
* If max_files > 0, retain only the last max_files and delete previous.
|
* If max_files > 0, retain only the last max_files and delete previous.
|
||||||
*/
|
*/
|
||||||
template<typename Mutex, typename FileNameCalc = minute_filename_calculator>
|
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:
|
public:
|
||||||
// create every minute file sink which rotates on given time
|
// 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,
|
filename_t base_filename, bool truncate = false, uint16_t max_files = 0,
|
||||||
int rotation_minute = 0, const file_event_handlers &event_handlers = {})
|
int rotation_minute = 0, const file_event_handlers &event_handlers = {})
|
||||||
: base_filename_(std::move(base_filename))
|
: base_filename_(std::move(base_filename))
|
||||||
@ -61,10 +61,7 @@ public:
|
|||||||
, filenames_q_()
|
, 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 now = log_clock::now();
|
||||||
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
|
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
|
||||||
@ -193,8 +190,8 @@ private:
|
|||||||
bool remove_init_file_;
|
bool remove_init_file_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using minute_file_sink_mt = minute_file_sink<std::mutex>;
|
using minute_interval_file_sink_mt = minute_interval_file_sink<std::mutex>;
|
||||||
using minute_file_sink_st = minute_file_sink<details::null_mutex>;
|
using minute_interval_file_sink_st = minute_interval_file_sink<details::null_mutex>;
|
||||||
|
|
||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
|
|
||||||
@ -202,16 +199,16 @@ using minute_file_sink_st = minute_file_sink<details::null_mutex>;
|
|||||||
// factory functions
|
// factory functions
|
||||||
//
|
//
|
||||||
template<typename Factory = spdlog::synchronous_factory>
|
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 = {})
|
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>
|
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 = {})
|
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
|
} // namespace spdlog
|
||||||
|
Loading…
Reference in New Issue
Block a user