diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 1a920c03..fa4731ae 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -312,4 +312,8 @@ inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter) _formatter = msg_formatter; } - +inline void spdlog::logger::flush() { + for (auto& sink : _sinks) { + sink->flush(); + } +} \ No newline at end of file diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index cf97fc80..7a5a31a7 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -107,6 +107,7 @@ public: void set_pattern(const std::string&); void set_formatter(formatter_ptr); + void flush(); protected: virtual void _log_msg(details::log_msg&); diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index 55411721..12d63ea8 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -58,8 +58,6 @@ public: _sink_it(msg); } - virtual void flush() = 0; - protected: virtual void _sink_it(const details::log_msg& msg) = 0; Mutex _mutex; diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 0905d52f..88c423a0 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -35,6 +35,7 @@ class sink public: virtual ~sink() {} virtual void log(const details::log_msg& msg) = 0; + virtual void flush() = 0; }; } } diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index 7d729743..15a96fee 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -78,6 +78,8 @@ public: ::syslog(syslog_prio_from_level(msg), "%s", msg.formatted.str().c_str()); } + virtual void flush() override { + } private: