diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 8ae67bf0..8e1f600b 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -87,6 +87,10 @@ public: } + void flush() { + std::fflush(_fd); + } + void close() { if (_fd) diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index f1647ae0..55411721 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -58,6 +58,7 @@ public: _sink_it(msg); } + virtual void flush() = 0; protected: virtual void _sink_it(const details::log_msg& msg) = 0; diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 9ec8f46b..0e705337 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -80,6 +80,10 @@ public: _file_helper.open(calc_filename(_base_filename, 0, _extension)); } + virtual void flush() override { + _file_helper.flush(); + } + protected: void _sink_it(const details::log_msg& msg) override { @@ -167,6 +171,10 @@ public: _file_helper.open(calc_filename(_base_filename, _extension)); } + virtual void flush() override { + _file_helper.flush(); + } + protected: void _sink_it(const details::log_msg& msg) override { diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h index 2cd416a9..992b3b73 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -40,6 +40,9 @@ protected: void _sink_it(const details::log_msg&) override {} + void flush() override + {} + }; typedef null_sink null_sink_st; typedef null_sink null_sink_mt; diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 91580301..7b6b9db3 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -51,6 +51,11 @@ protected: if (_force_flush) _ostream.flush(); } + + virtual void flush() override { + _ostream.flush(); + } + std::ostream& _ostream; bool _force_flush; };