Merge pull request #90 from divaykin/sink-flush

explicit flush()
This commit is contained in:
Gabi Melman 2015-05-09 15:42:03 +03:00
commit d45fc34c97
9 changed files with 29 additions and 2 deletions

View File

@ -87,6 +87,10 @@ public:
} }
void flush() {
std::fflush(_fd);
}
void close() void close()
{ {
if (_fd) if (_fd)

View File

@ -312,4 +312,8 @@ inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter)
_formatter = msg_formatter; _formatter = msg_formatter;
} }
inline void spdlog::logger::flush() {
for (auto& sink : _sinks) {
sink->flush();
}
}

View File

@ -107,6 +107,7 @@ public:
void set_pattern(const std::string&); void set_pattern(const std::string&);
void set_formatter(formatter_ptr); void set_formatter(formatter_ptr);
void flush();
protected: protected:
virtual void _log_msg(details::log_msg&); virtual void _log_msg(details::log_msg&);

View File

@ -58,7 +58,6 @@ public:
_sink_it(msg); _sink_it(msg);
} }
protected: protected:
virtual void _sink_it(const details::log_msg& msg) = 0; virtual void _sink_it(const details::log_msg& msg) = 0;
Mutex _mutex; Mutex _mutex;

View File

@ -80,6 +80,10 @@ public:
_file_helper.open(calc_filename(_base_filename, 0, _extension)); _file_helper.open(calc_filename(_base_filename, 0, _extension));
} }
virtual void flush() override {
_file_helper.flush();
}
protected: protected:
void _sink_it(const details::log_msg& msg) override void _sink_it(const details::log_msg& msg) override
{ {
@ -167,6 +171,10 @@ public:
_file_helper.open(calc_filename(_base_filename, _extension)); _file_helper.open(calc_filename(_base_filename, _extension));
} }
virtual void flush() override {
_file_helper.flush();
}
protected: protected:
void _sink_it(const details::log_msg& msg) override void _sink_it(const details::log_msg& msg) override
{ {

View File

@ -40,6 +40,9 @@ protected:
void _sink_it(const details::log_msg&) override void _sink_it(const details::log_msg&) override
{} {}
void flush() override
{}
}; };
typedef null_sink<details::null_mutex> null_sink_st; typedef null_sink<details::null_mutex> null_sink_st;
typedef null_sink<std::mutex> null_sink_mt; typedef null_sink<std::mutex> null_sink_mt;

View File

@ -51,6 +51,11 @@ protected:
if (_force_flush) if (_force_flush)
_ostream.flush(); _ostream.flush();
} }
virtual void flush() override {
_ostream.flush();
}
std::ostream& _ostream; std::ostream& _ostream;
bool _force_flush; bool _force_flush;
}; };

View File

@ -35,6 +35,7 @@ class sink
public: public:
virtual ~sink() {} virtual ~sink() {}
virtual void log(const details::log_msg& msg) = 0; virtual void log(const details::log_msg& msg) = 0;
virtual void flush() = 0;
}; };
} }
} }

View File

@ -78,6 +78,8 @@ public:
::syslog(syslog_prio_from_level(msg), "%s", msg.formatted.str().c_str()); ::syslog(syslog_prio_from_level(msg), "%s", msg.formatted.str().c_str());
} }
virtual void flush() override {
}
private: private: