Agora  1.2.0
Agora project
ostream_sink.h
Go to the documentation of this file.
1 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
3 
4 #pragma once
5 
8 
9 #include <mutex>
10 #include <ostream>
11 
12 namespace spdlog {
13 namespace sinks {
14 template<typename Mutex>
15 class ostream_sink final : public base_sink<Mutex>
16 {
17 public:
18  explicit ostream_sink(std::ostream &os, bool force_flush = false)
19  : ostream_(os)
20  , force_flush_(force_flush)
21  {}
22  ostream_sink(const ostream_sink &) = delete;
23  ostream_sink &operator=(const ostream_sink &) = delete;
24 
25 protected:
26  void sink_it_(const details::log_msg &msg) override
27  {
28  memory_buf_t formatted;
29  base_sink<Mutex>::formatter_->format(msg, formatted);
30  ostream_.write(formatted.data(), static_cast<std::streamsize>(formatted.size()));
31  if (force_flush_)
32  {
33  ostream_.flush();
34  }
35  }
36 
37  void flush_() override
38  {
39  ostream_.flush();
40  }
41 
42  std::ostream &ostream_;
44 };
45 
48 
49 } // namespace sinks
50 } // namespace spdlog
spdlog::sinks::ostream_sink::ostream_sink
ostream_sink(std::ostream &os, bool force_flush=false)
Definition: ostream_sink.h:18
base_sink.h
spdlog::sinks::ostream_sink::flush_
void flush_() override
Definition: ostream_sink.h:37
fmt::v8::detail::buffer::size
constexpr auto size() const -> size_t
Definition: core.h:820
null_mutex.h
fmt::v8::basic_memory_buffer
Definition: format.h:677
spdlog
Definition: async.h:25
spdlog::sinks::ostream_sink::force_flush_
bool force_flush_
Definition: ostream_sink.h:43
spdlog::sinks::base_sink
Definition: base_sink.h:19
spdlog::sinks::ostream_sink::sink_it_
void sink_it_(const details::log_msg &msg) override
Definition: ostream_sink.h:26
fmt::v8::detail::buffer::data
auto data() -> T *
Definition: core.h:826
spdlog::details::log_msg
Definition: log_msg.h:11
spdlog::sinks::ostream_sink::operator=
ostream_sink & operator=(const ostream_sink &)=delete
spdlog::sinks::ostream_sink
Definition: ostream_sink.h:15
spdlog::sinks::ostream_sink::ostream_
std::ostream & ostream_
Definition: ostream_sink.h:42