From 0be736c7fc6bed0733095ca2a951eb86ef1683dc Mon Sep 17 00:00:00 2001 From: Sam Brkopac Date: Mon, 22 Aug 2016 13:31:43 -0700 Subject: [PATCH] Added the ability to truncate the basic file logger. Added the ability to truncate the basic file logger. --- include/spdlog/details/spdlog_impl.h | 8 ++++---- include/spdlog/sinks/file_sinks.h | 5 +++-- include/spdlog/spdlog.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index 4ef085b6..fb4e6f84 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -36,14 +36,14 @@ inline void spdlog::drop(const std::string &name) } // Create multi/single threaded simple file logger -inline std::shared_ptr spdlog::basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool force_flush) +inline std::shared_ptr spdlog::basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool force_flush, bool truncate) { - return create(logger_name, filename, force_flush); + return create(logger_name, filename, force_flush, truncate); } -inline std::shared_ptr spdlog::basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush) +inline std::shared_ptr spdlog::basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush, bool truncate) { - return create(logger_name, filename, force_flush); + return create(logger_name, filename, force_flush, truncate); } // Create multi/single threaded rotating file logger diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index a687f99f..ff767593 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -30,10 +30,11 @@ class simple_file_sink : public base_sink < Mutex > { public: explicit simple_file_sink(const filename_t &filename, - bool force_flush = false) : + bool force_flush = false, + bool truncate = false) : _file_helper(force_flush) { - _file_helper.open(filename); + _file_helper.open(filename, truncate); } void flush() override { diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index ff1b6022..e2b8ba4b 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -71,8 +71,8 @@ void set_sync_mode(); // // Create and register multi/single basic file logger // -std::shared_ptr basic_logger_mt(const std::string& logger_name, const filename_t& filename,bool force_flush = false); -std::shared_ptr basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush = false); +std::shared_ptr basic_logger_mt(const std::string& logger_name, const filename_t& filename,bool force_flush = false, bool truncate = false); +std::shared_ptr basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush = false, bool truncate = false); // // Create and register multi/single threaded rotating file logger