Photon 1.0.0
Loading...
Searching...
No Matches
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
12namespace spdlog
13{
14 namespace sinks
15 {
16 template <typename Mutex>
17 class ostream_sink final : public base_sink<Mutex>
18 {
19 public:
20 explicit ostream_sink(std::ostream& os, bool force_flush = false)
21 : ostream_(os), force_flush_(force_flush)
22 {
23 }
24 ostream_sink(const ostream_sink&) = delete;
26
27 protected:
28 void sink_it_(const details::log_msg& msg) override
29 {
30 memory_buf_t formatted;
31 base_sink<Mutex>::formatter_->format(msg, formatted);
32 ostream_.write(formatted.data(), static_cast<std::streamsize>(formatted.size()));
33 if (force_flush_)
34 {
36 }
37 }
38
39 void flush_() override
40 {
41 ostream_.flush();
42 }
43
44 std::ostream& ostream_;
46 };
47
50
51 } // namespace sinks
52} // namespace spdlog
Definition base_sink.h:22
void flush() final
Definition base_sink-inl.h:35
Definition ostream_sink.h:18
std::ostream & ostream_
Definition ostream_sink.h:44
bool force_flush_
Definition ostream_sink.h:45
ostream_sink & operator=(const ostream_sink &)=delete
ostream_sink(const ostream_sink &)=delete
void sink_it_(const details::log_msg &msg) override
Definition ostream_sink.h:28
void flush_() override
Definition ostream_sink.h:39
ostream_sink(std::ostream &os, bool force_flush=false)
Definition ostream_sink.h:20
ostream_sink< details::null_mutex > ostream_sink_st
Definition ostream_sink.h:49
ostream_sink< std::mutex > ostream_sink_mt
Definition ostream_sink.h:48
Definition async.h:26
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:173
Definition log_msg.h:14