spdlog
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 {
13namespace sinks {
14template<typename Mutex>
15class ostream_sink final : public base_sink<Mutex>
16{
17public:
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;
24
25protected:
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 {
34 }
35 }
36
37 void flush_() override
38 {
40 }
41
44};
45
48
49} // namespace sinks
50} // namespace spdlog
ostream_sink & operator=(const ostream_sink &)=delete
ostream_sink(const ostream_sink &)=delete
void sink_it_(const details::log_msg &msg) override
ostream_sink(std::ostream &os, bool force_flush=false)
T flush(T... args)
Definition async.h:25
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:116
T write(T... args)