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
42  : Sink (sink)
43  , sink_(sink)
44  , prefix_(prefix)
45  {
46  }
47 
48  explicit
49  WrappedSink (beast::Journal const& journal, std::string const& prefix = "")
50  : WrappedSink (journal.sink(), prefix)
51  {
52  }
53 
54  void prefix (std::string const& s)
55  {
56  prefix_ = s;
57  }
58 
59  bool
60  active (beast::severities::Severity level) const override
61  {
62  return sink_.active (level);
63  }
64 
65  bool
66  console () const override
67  {
68  return sink_.console ();
69  }
70 
71  void console (bool output) override
72  {
73  sink_.console (output);
74  }
75 
77  threshold() const override
78  {
79  return sink_.threshold();
80  }
81 
82  void threshold (beast::severities::Severity thresh) override
83  {
84  sink_.threshold (thresh);
85  }
86 
87  void write (beast::severities::Severity level, std::string const& text) override
88  {
89  using beast::Journal;
90  sink_.write (level, prefix_ + text);
91  }
92 };
93 
94 }
95 
96 #endif
beast::Journal::Sink
Abstraction for the underlying message destination.
Definition: Journal.h:76
beast::WrappedSink::console
bool console() const override
Returns true if a message is also written to the Output Window (MSVC).
Definition: WrappedSink.h:66
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:87
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:71
beast::WrappedSink::WrappedSink
WrappedSink(beast::Journal const &journal, std::string const &prefix="")
Definition: WrappedSink.h:49
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:77
beast::WrappedSink::threshold
void threshold(beast::severities::Severity thresh) override
Set the minimum severity this sink will report.
Definition: WrappedSink.h:82
beast::Journal::Sink::active
virtual bool active(Severity level) const
Returns true if text at the passed severity produces output.
Definition: beast_Journal.cpp:83
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:88
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
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:60
beast::Journal::Sink::threshold
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Definition: beast_Journal.cpp:98
beast::severities::Severity
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:32
beast::WrappedSink::prefix
void prefix(std::string const &s)
Definition: WrappedSink.h:54
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:41
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:582