diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 68ecec87..91580301 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -39,7 +39,7 @@ template class ostream_sink: public base_sink { public: - explicit ostream_sink(std::ostream& os) :_ostream(os) {} + explicit ostream_sink(std::ostream& os, bool force_flush=false) :_ostream(os), _force_flush(force_flush) {} ostream_sink(const ostream_sink&) = delete; ostream_sink& operator=(const ostream_sink&) = delete; virtual ~ostream_sink() = default; @@ -48,8 +48,11 @@ protected: virtual void _sink_it(const details::log_msg& msg) override { _ostream.write(msg.formatted.data(), msg.formatted.size()); + if (_force_flush) + _ostream.flush(); } std::ostream& _ostream; + bool _force_flush; }; typedef ostream_sink ostream_sink_mt; diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index b633b2dc..e944e273 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -38,7 +38,7 @@ template class stdout_sink : public ostream_sink { public: - stdout_sink() : ostream_sink(std::cout) {} + stdout_sink() : ostream_sink(std::cout, true) {} }; @@ -50,7 +50,7 @@ template class stderr_sink : public ostream_sink { public: - stderr_sink() : ostream_sink(std::cerr) {} + stderr_sink() : ostream_sink(std::cerr, true) {} }; typedef stderr_sink stderr_sink_mt;