rippled
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 <ripple/beast/utility/Journal.h>
24 
25 namespace 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 {
35 private:
38 
39 public:
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
55  prefix(std::string const& s)
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
beast::Journal::Sink
Abstraction for the underlying message destination.
Definition: Journal.h:74
beast::WrappedSink::console
bool console() const override
Returns true if a message is also written to the Output Window (MSVC).
Definition: WrappedSink.h:67
beast::WrappedSink::write
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Definition: WrappedSink.h:91
std::string
STL class.
beast::WrappedSink::console
void console(bool output) override
Set whether messages are also written to the Output Window (MSVC).
Definition: WrappedSink.h:73
beast::WrappedSink::WrappedSink
WrappedSink(beast::Journal const &journal, std::string const &prefix="")
Definition: WrappedSink.h:47
beast::WrappedSink::sink_
beast::Journal::Sink & sink_
Definition: WrappedSink.h:36
beast::WrappedSink::threshold
beast::severities::Severity threshold() const override
Returns the minimum severity level this sink will report.
Definition: WrappedSink.h:79
beast::WrappedSink::threshold
void threshold(beast::severities::Severity thresh) override
Set the minimum severity this sink will report.
Definition: WrappedSink.h:85
beast::Journal::Sink::active
virtual bool active(Severity level) const
Returns true if text at the passed severity produces output.
Definition: beast_Journal.cpp:88
beast::Journal::Sink::Sink
Sink()=delete
beast::Journal::Sink::console
virtual bool console() const
Returns true if a message is also written to the Output Window (MSVC).
Definition: beast_Journal.cpp:94
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
beast::WrappedSink::prefix_
std::string prefix_
Definition: WrappedSink.h:37
beast::WrappedSink::active
bool active(beast::severities::Severity level) const override
Returns true if text at the passed severity produces output.
Definition: WrappedSink.h:61
beast::Journal::Sink::threshold
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Definition: beast_Journal.cpp:106
beast::severities::Severity
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:31
beast::WrappedSink::prefix
void prefix(std::string const &s)
Definition: WrappedSink.h:55
beast::WrappedSink
Wraps a Journal::Sink to prefix its output with a string.
Definition: WrappedSink.h:33
beast::WrappedSink::WrappedSink
WrappedSink(beast::Journal::Sink &sink, std::string const &prefix="")
Definition: WrappedSink.h:40
beast::Journal::Sink::write
virtual void write(Severity level, std::string const &text)=0
Write text to the sink at the specified severity.
beast
Definition: base_uint.h:641