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;