mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
Update as per comments
This commit is contained in:
parent
86daaf2575
commit
b1c1e4d165
@ -3,7 +3,7 @@
|
||||
//File: minute_file_sink to support every 1 min file rotation.
|
||||
//example driver code:
|
||||
// auto duration{std::chrono::minutes{1}};
|
||||
//auto logger = spdlog::periodic_logger_mt("periodic_logger", "logs/min-log.txt",false,60,duration);
|
||||
//auto logger = spdlog::periodic_logger_mt("periodic_logger", "logs/min-log.txt",duration,60,false);
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -50,18 +50,26 @@ class periodic_file_sink final : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
// create every periodic file sink which rotates on given time
|
||||
periodic_file_sink(
|
||||
/*periodic_file_sink(
|
||||
filename_t base_filename, bool truncate = false, uint16_t max_files = 0,
|
||||
std::chrono::duration<int> rotation_period = 0, const file_event_handlers &event_handlers = {})
|
||||
|
||||
*/
|
||||
periodic_file_sink(
|
||||
filename_t base_filename,
|
||||
std::chrono::minutes rotation_interval,
|
||||
uint16_t max_files,
|
||||
bool truncate_first = false,
|
||||
const file_event_handlers &event_handlers = {})
|
||||
: base_filename_(std::move(base_filename))
|
||||
, file_helper_{event_handlers}
|
||||
, truncate_(truncate)
|
||||
, truncate_(truncate_first)
|
||||
, max_files_(max_files)
|
||||
,rotation_p_(rotation_period)
|
||||
,rotation_p_(rotation_interval)
|
||||
, filenames_q_()
|
||||
{
|
||||
|
||||
if (rotation_period <= std::chrono::minutes(0))
|
||||
if (rotation_interval <= std::chrono::minutes(0))
|
||||
{
|
||||
throw_spdlog_ex("periodic_file_sink: Invalid rotation time in ctor");
|
||||
}
|
||||
@ -76,6 +84,12 @@ public:
|
||||
{
|
||||
init_filenames_q_();
|
||||
}
|
||||
|
||||
if (max_files > 2000)
|
||||
{
|
||||
throw_spdlog_ex("periodic_file_sink: max_files param exceeds max of 2000");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
filename_t filename()
|
||||
@ -202,16 +216,16 @@ using periodic_file_sink_st = periodic_file_sink<details::null_mutex>;
|
||||
// factory functions
|
||||
//
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> periodic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
||||
uint16_t max_files = 0, std::chrono::duration<int> period = 1, const file_event_handlers &event_handlers = {})
|
||||
inline std::shared_ptr<logger> periodic_logger_mt(const std::string &logger_name, const filename_t &filename,std::chrono::minutes period = 1,uint16_t max_files = 0, bool truncate = false,
|
||||
const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::periodic_file_sink_mt>(logger_name, filename, truncate, max_files, period ,event_handlers);
|
||||
return Factory::template create<sinks::periodic_file_sink_mt>(logger_name, filename,period,max_files, truncate, event_handlers);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> periodic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false,
|
||||
uint16_t max_files = 0,std::chrono::duration<int> period = 1, const file_event_handlers &event_handlers = {})
|
||||
inline std::shared_ptr<logger> periodic_logger_st(const std::string &logger_name, const filename_t &filename,std::chrono::minutes period = 1,uint16_t max_files = 0, bool truncate = false,
|
||||
const file_event_handlers &event_handlers = {})
|
||||
{
|
||||
return Factory::template create<sinks::periodic_file_sink_st>(logger_name, filename, truncate, max_files, period, event_handlers);
|
||||
return Factory::template create<sinks::periodic_file_sink_st>(logger_name, filename,period, max_files,truncate, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
Loading…
Reference in New Issue
Block a user