From 56678a5f6a7a26e0c0f71d4c997f3a11394ce13e Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 1 Oct 2016 16:37:33 +0300 Subject: [PATCH] added set_force_flush(bool) to simple file sink for performance benchmarks --- include/spdlog/sinks/file_sinks.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index fad21fe1..550a9bb4 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -29,7 +29,7 @@ template class simple_file_sink : public base_sink < Mutex > { public: - explicit simple_file_sink(const filename_t &filename, bool truncate = false) + explicit simple_file_sink(const filename_t &filename, bool truncate = false):_force_flush(false) { _file_helper.open(filename, truncate); } @@ -37,14 +37,21 @@ public: { _file_helper.flush(); } + void set_force_flush(bool force_flush) + { + _force_flush = force_flush; + } protected: void _sink_it(const details::log_msg& msg) override { - _file_helper.write(msg); + _file_helper.write(msg); + if(_force_flush) + _file_helper.flush(); } private: details::file_helper _file_helper; + bool _force_flush; }; typedef simple_file_sink simple_file_sink_mt;