mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-16 01:37:58 +00:00
Compare commits
9 Commits
23dfb4e2f9
...
0fac33781d
Author | SHA1 | Date | |
---|---|---|---|
|
0fac33781d | ||
|
3135b6a33d | ||
|
2686ae2322 | ||
|
a709e29586 | ||
|
dd46579cb4 | ||
|
f4b7210e7b | ||
|
05a0b0d7b0 | ||
|
c1f4d7506a | ||
|
b6ba0be550 |
@ -7,6 +7,7 @@
|
||||
#include <spdlog/details/file_helper.h>
|
||||
#include <spdlog/details/null_mutex.h>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <spdlog/fmt/chrono.h>
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <spdlog/details/os.h>
|
||||
#include <spdlog/details/circular_q.h>
|
||||
@ -36,6 +37,19 @@ struct daily_filename_calculator
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Generator of daily log file names with strftime format.
|
||||
*/
|
||||
struct daily_filename_format_calculator
|
||||
{
|
||||
static filename_t calc_filename (const filename_t &filename, const tm &now_tm)
|
||||
{
|
||||
// generate fmt datetime format string, e.g. {:%Y-%m-%d}.
|
||||
filename_t fmt_filename = fmt::format(SPDLOG_FILENAME_T ("{{:{}}}"), filename);
|
||||
return fmt::format(fmt_filename, now_tm);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Rotating file sink based on date.
|
||||
* If truncate != false , the created file will be truncated.
|
||||
@ -182,6 +196,8 @@ private:
|
||||
|
||||
using daily_file_sink_mt = daily_file_sink<std::mutex>;
|
||||
using daily_file_sink_st = daily_file_sink<details::null_mutex>;
|
||||
using daily_file_format_sink_mt = daily_file_sink<std::mutex, daily_filename_format_calculator>;
|
||||
using daily_file_format_sink_st = daily_file_sink<details::null_mutex, daily_filename_format_calculator>;
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
@ -195,10 +211,24 @@ inline std::shared_ptr<logger> daily_logger_mt(
|
||||
return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute, truncate, max_files);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline 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)
|
||||
{
|
||||
return Factory::template create<sinks::daily_file_format_sink_mt>(logger_name, filename, hour, minute, truncate, max_files);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
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)
|
||||
{
|
||||
return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute, truncate, max_files);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline 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)
|
||||
{
|
||||
return Factory::template create<sinks::daily_file_format_sink_st>(logger_name, filename, hour, minute, truncate, max_files);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
Loading…
Reference in New Issue
Block a user