RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
OStreamSink.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <ostream>
6
7namespace RST::Log {
8
10 class OStreamSink : public ASink {
11 public:
12 explicit OStreamSink(std::ostream& stream) : _stream(stream) {}
13
14 protected:
15 void log(const LogMessage& message) override
16 {
17 const std::string_view line = formatted(message);
18 _stream.write(line.data(), static_cast<std::streamsize>(line.size()));
19 _stream.put('\n');
20 }
21
22 void flushSink() override { _stream.flush(); }
23
24 private:
25 std::ostream& _stream;
26 };
27
28}
Base class for sinks: handles the level, the pattern and the locking.
Definition ASink.hpp:17
std::string_view formatted(const LogMessage &message)
The message formatted with the sink pattern.
Writes plain lines to a std::ostream, which must outlive the sink.
Definition OStreamSink.hpp:10
void log(const LogMessage &message) override
Writes one message; called with the sink mutex locked.
Definition OStreamSink.hpp:15
OStreamSink(std::ostream &stream)
Definition OStreamSink.hpp:12
void flushSink() override
Flushes the output; called with the sink mutex locked.
Definition OStreamSink.hpp:22
Thread-safe logging: loggers, sinks, patterns and macros.
Definition Terminal.hpp:8
A log record as passed to the sinks.
Definition LogMessage.hpp:18