xrpld
Loading...
Searching...
No Matches
WrappedSink.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4
5#include <utility>
6
7namespace beast {
8
10
11// A WrappedSink both is a Sink and has a Sink:
12// o It inherits from Sink so it has the correct interface.
13// o It has a sink (reference) so it preserves the passed write() behavior.
14// The data inherited from the base class is ignored.
16{
17private:
20
21public:
23 : Sink(sink), sink_(sink), prefix_(std::move(prefix))
24 {
25 }
26
27 explicit WrappedSink(beast::Journal const& journal, std::string const& prefix = "")
28 : WrappedSink(journal.sink(), prefix)
29 {
30 }
31
32 void
34 {
35 prefix_ = s;
36 }
37
38 [[nodiscard]] bool
39 active(beast::Severity level) const override
40 {
41 return sink_.active(level);
42 }
43
44 [[nodiscard]] bool
45 console() const override
46 {
47 return sink_.console();
48 }
49
50 void
51 console(bool output) override
52 {
53 sink_.console(output);
54 }
55
56 [[nodiscard]] beast::Severity
57 threshold() const override
58 {
59 return sink_.threshold();
60 }
61
62 void
63 threshold(beast::Severity thresh) override
64 {
65 sink_.threshold(thresh);
66 }
67
68 void
69 write(beast::Severity level, std::string const& text) override
70 {
71 using beast::Journal;
72 sink_.write(level, prefix_ + text);
73 }
74
75 void
76 writeAlways(Severity level, std::string const& text) override
77 {
78 using beast::Journal;
79 sink_.writeAlways(level, prefix_ + text);
80 }
81};
82
83} // namespace beast
Abstraction for the underlying message destination.
Definition Journal.h:51
Sink(Sink const &sink)=default
A generic endpoint for log messages.
Definition Journal.h:38
void console(bool output) override
Set whether messages are also written to the Output Window (MSVC).
Definition WrappedSink.h:51
WrappedSink(beast::Journal const &journal, std::string const &prefix="")
Definition WrappedSink.h:27
bool console() const override
Returns true if a message is also written to the Output Window (MSVC).
Definition WrappedSink.h:45
bool active(beast::Severity level) const override
Returns true if text at the passed severity produces output.
Definition WrappedSink.h:39
void writeAlways(Severity level, std::string const &text) override
Bypass filter and write text to the sink at the specified severity.
Definition WrappedSink.h:76
beast::Journal::Sink & sink_
Definition WrappedSink.h:18
void threshold(beast::Severity thresh) override
Set the minimum severity this sink will report.
Definition WrappedSink.h:63
void prefix(std::string const &s)
Definition WrappedSink.h:33
std::string prefix_
Definition WrappedSink.h:19
void write(beast::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Definition WrappedSink.h:69
beast::Severity threshold() const override
Returns the minimum severity level this sink will report.
Definition WrappedSink.h:57
WrappedSink(beast::Journal::Sink &sink, std::string prefix="")
Definition WrappedSink.h:22
Severity
Severity level / threshold of a Journal message.
Definition Journal.h:11
STL namespace.