rippled
Loading...
Searching...
No Matches
WrappedSink.h
1#ifndef BEAST_UTILITY_WRAPPEDSINK_H_INCLUDED
2#define BEAST_UTILITY_WRAPPEDSINK_H_INCLUDED
3
4#include <xrpl/beast/utility/Journal.h>
5
6namespace beast {
7
10// A WrappedSink both is a Sink and has a Sink:
11// o It inherits from Sink so it has the correct interface.
12// o It has a sink (reference) so it preserves the passed write() behavior.
13// The data inherited from the base class is ignored.
15{
16private:
19
20public:
21 explicit WrappedSink(
23 std::string const& prefix = "")
24 : Sink(sink), sink_(sink), prefix_(prefix)
25 {
26 }
27
28 explicit WrappedSink(
29 beast::Journal const& journal,
30 std::string const& prefix = "")
31 : WrappedSink(journal.sink(), prefix)
32 {
33 }
34
35 void
37 {
38 prefix_ = s;
39 }
40
41 bool
42 active(beast::severities::Severity level) const override
43 {
44 return sink_.active(level);
45 }
46
47 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
60 threshold() const override
61 {
62 return sink_.threshold();
63 }
64
65 void
67 {
68 sink_.threshold(thresh);
69 }
70
71 void
72 write(beast::severities::Severity level, std::string const& text) override
73 {
74 using beast::Journal;
75 sink_.write(level, prefix_ + text);
76 }
77
78 void
79 writeAlways(severities::Severity level, std::string const& text) override
80 {
81 using beast::Journal;
82 sink_.writeAlways(level, prefix_ + text);
83 }
84};
85
86} // namespace beast
87
88#endif
Abstraction for the underlying message destination.
Definition Journal.h:57
virtual bool active(Severity level) const
Returns true if text at the passed severity produces output.
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
virtual bool console() const
Returns true if a message is also written to the Output Window (MSVC).
virtual void write(Severity level, std::string const &text)=0
Write text to the sink at the specified severity.
virtual void writeAlways(Severity level, std::string const &text)=0
Bypass filter and write text to the sink at the specified severity.
A generic endpoint for log messages.
Definition Journal.h:41
Wraps a Journal::Sink to prefix its output with a string.
Definition WrappedSink.h:15
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:28
bool console() const override
Returns true if a message is also written to the Output Window (MSVC).
Definition WrappedSink.h:48
WrappedSink(beast::Journal::Sink &sink, std::string const &prefix="")
Definition WrappedSink.h:21
beast::Journal::Sink & sink_
Definition WrappedSink.h:17
beast::severities::Severity threshold() const override
Returns the minimum severity level this sink will report.
Definition WrappedSink.h:60
void writeAlways(severities::Severity level, std::string const &text) override
Bypass filter and write text to the sink at the specified severity.
Definition WrappedSink.h:79
void prefix(std::string const &s)
Definition WrappedSink.h:36
std::string prefix_
Definition WrappedSink.h:18
void threshold(beast::severities::Severity thresh) override
Set the minimum severity this sink will report.
Definition WrappedSink.h:66
bool active(beast::severities::Severity level) const override
Returns true if text at the passed severity produces output.
Definition WrappedSink.h:42
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Definition WrappedSink.h:72
Severity
Severity level / threshold of a Journal message.
Definition Journal.h:13