rippled
Loading...
Searching...
No Matches
WrappedSink.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef BEAST_UTILITY_WRAPPEDSINK_H_INCLUDED
21#define BEAST_UTILITY_WRAPPEDSINK_H_INCLUDED
22
23#include <xrpl/beast/utility/Journal.h>
24
25namespace beast {
26
29// A WrappedSink both is a Sink and has a Sink:
30// o It inherits from Sink so it has the correct interface.
31// o It has a sink (reference) so it preserves the passed write() behavior.
32// The data inherited from the base class is ignored.
34{
35private:
38
39public:
40 explicit WrappedSink(
42 std::string const& prefix = "")
43 : Sink(sink), sink_(sink), prefix_(prefix)
44 {
45 }
46
47 explicit WrappedSink(
48 beast::Journal const& journal,
49 std::string const& prefix = "")
50 : WrappedSink(journal.sink(), prefix)
51 {
52 }
53
54 void
56 {
57 prefix_ = s;
58 }
59
60 bool
61 active(beast::severities::Severity level) const override
62 {
63 return sink_.active(level);
64 }
65
66 bool
67 console() const override
68 {
69 return sink_.console();
70 }
71
72 void
73 console(bool output) override
74 {
75 sink_.console(output);
76 }
77
79 threshold() const override
80 {
81 return sink_.threshold();
82 }
83
84 void
86 {
87 sink_.threshold(thresh);
88 }
89
90 void
91 write(beast::severities::Severity level, std::string const& text) override
92 {
93 using beast::Journal;
94 sink_.write(level, prefix_ + text);
95 }
96};
97
98} // namespace beast
99
100#endif
Abstraction for the underlying message destination.
Definition: Journal.h:75
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.
A generic endpoint for log messages.
Definition: Journal.h:59
Wraps a Journal::Sink to prefix its output with a string.
Definition: WrappedSink.h:34
void console(bool output) override
Set whether messages are also written to the Output Window (MSVC).
Definition: WrappedSink.h:73
WrappedSink(beast::Journal const &journal, std::string const &prefix="")
Definition: WrappedSink.h:47
bool console() const override
Returns true if a message is also written to the Output Window (MSVC).
Definition: WrappedSink.h:67
WrappedSink(beast::Journal::Sink &sink, std::string const &prefix="")
Definition: WrappedSink.h:40
beast::Journal::Sink & sink_
Definition: WrappedSink.h:36
beast::severities::Severity threshold() const override
Returns the minimum severity level this sink will report.
Definition: WrappedSink.h:79
void prefix(std::string const &s)
Definition: WrappedSink.h:55
std::string prefix_
Definition: WrappedSink.h:37
void threshold(beast::severities::Severity thresh) override
Set the minimum severity this sink will report.
Definition: WrappedSink.h:85
bool active(beast::severities::Severity level) const override
Returns true if text at the passed severity produces output.
Definition: WrappedSink.h:61
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Definition: WrappedSink.h:91
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:31