|
|
@ -11,6 +11,7 @@
|
|
|
|
#include <chrono>
|
|
|
|
#include <chrono>
|
|
|
|
#include <mutex>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
|
|
namespace spdlog {
|
|
|
|
namespace spdlog {
|
|
|
|
namespace sinks {
|
|
|
|
namespace sinks {
|
|
|
@ -23,6 +24,8 @@ class rotating_file_sink final : public base_sink<Mutex>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false);
|
|
|
|
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false);
|
|
|
|
|
|
|
|
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files,
|
|
|
|
|
|
|
|
filename_t compress_extension, std::function<void(filename_t)> compress_callback, bool rotate_on_open = false);
|
|
|
|
static filename_t calc_filename(const filename_t &filename, std::size_t index);
|
|
|
|
static filename_t calc_filename(const filename_t &filename, std::size_t index);
|
|
|
|
filename_t filename();
|
|
|
|
filename_t filename();
|
|
|
|
|
|
|
|
|
|
|
@ -42,11 +45,19 @@ private:
|
|
|
|
// return true on success, false otherwise.
|
|
|
|
// return true on success, false otherwise.
|
|
|
|
bool rename_file_(const filename_t &src_filename, const filename_t &target_filename);
|
|
|
|
bool rename_file_(const filename_t &src_filename, const filename_t &target_filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// runs given compress_
|
|
|
|
|
|
|
|
void call_compressor_callback();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Common init called from constructor
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
|
|
|
|
filename_t base_filename_;
|
|
|
|
filename_t base_filename_;
|
|
|
|
std::size_t max_size_;
|
|
|
|
std::size_t max_size_;
|
|
|
|
std::size_t max_files_;
|
|
|
|
std::size_t max_files_;
|
|
|
|
std::size_t current_size_;
|
|
|
|
std::size_t current_size_;
|
|
|
|
details::file_helper file_helper_;
|
|
|
|
details::file_helper file_helper_;
|
|
|
|
|
|
|
|
filename_t compress_extension_;
|
|
|
|
|
|
|
|
std::function<void(filename_t)> compress_callback_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
using rotating_file_sink_mt = rotating_file_sink<std::mutex>;
|
|
|
|
using rotating_file_sink_mt = rotating_file_sink<std::mutex>;
|
|
|
@ -65,12 +76,30 @@ inline std::shared_ptr<logger> rotating_logger_mt(
|
|
|
|
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files, rotate_on_open);
|
|
|
|
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files, rotate_on_open);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
|
|
|
|
inline std::shared_ptr<logger> rotating_logger_mt(
|
|
|
|
|
|
|
|
const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files,
|
|
|
|
|
|
|
|
const filename_t &compress_extension, std::function<void(filename_t)> compress_callback, bool rotate_on_open = false)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files,
|
|
|
|
|
|
|
|
compress_extension, std::move(compress_callback), rotate_on_open);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
inline std::shared_ptr<logger> rotating_logger_st(
|
|
|
|
inline std::shared_ptr<logger> rotating_logger_st(
|
|
|
|
const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false)
|
|
|
|
const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files, bool rotate_on_open = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Factory::template create<sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files, rotate_on_open);
|
|
|
|
return Factory::template create<sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files, rotate_on_open);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
|
|
|
|
inline std::shared_ptr<logger> rotating_logger_st(
|
|
|
|
|
|
|
|
const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files,
|
|
|
|
|
|
|
|
const filename_t &compress_extension, std::function<void(filename_t)> compress_callback, bool rotate_on_open = false)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Factory::template create<sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files,
|
|
|
|
|
|
|
|
compress_extension, std::move(compress_callback), rotate_on_open);
|
|
|
|
|
|
|
|
}
|
|
|
|
} // namespace spdlog
|
|
|
|
} // namespace spdlog
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SPDLOG_HEADER_ONLY
|
|
|
|
#ifdef SPDLOG_HEADER_ONLY
|
|
|
|