bitz-server  2.0.0
ostream_sink.h
1 //
2 // Copyright(c) 2015 Gabi Melman.
3 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 //
5 
6 #pragma once
7 
8 #include "../details/null_mutex.h"
9 #include "base_sink.h"
10 
11 #include <mutex>
12 #include <ostream>
13 
14 namespace spdlog {
15 namespace sinks {
16 template<class Mutex>
17 class ostream_sink : public base_sink<Mutex>
18 {
19 public:
20  explicit ostream_sink(std::ostream &os, bool force_flush = false)
21  : _ostream(os)
22  , _force_flush(force_flush)
23  {
24  }
25  ostream_sink(const ostream_sink &) = delete;
26  ostream_sink &operator=(const ostream_sink &) = delete;
27 
28 protected:
29  void _sink_it(const details::log_msg &msg) override
30  {
31  _ostream.write(msg.formatted.data(), msg.formatted.size());
32  if (_force_flush)
33  _ostream.flush();
34  }
35 
36  void _flush() override
37  {
38  _ostream.flush();
39  }
40 
41  std::ostream &_ostream;
42  bool _force_flush;
43 };
44 
47 
48 } // namespace sinks
49 } // namespace spdlog
const Char * data() const FMT_NOEXCEPT
Definition: format.h:3280
Definition: async_logger.h:26
std::size_t size() const
Definition: format.h:3271
Definition: log_msg.h:16
Definition: base_sink.h:23
Definition: ostream_sink.h:17