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