rippled
Loading...
Searching...
No Matches
beast_Journal.cpp
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#include <xrpl/beast/utility/Journal.h>
21#include <xrpl/beast/utility/instrumentation.h>
22
23namespace beast {
24
25//------------------------------------------------------------------------------
26
27// A Sink that does nothing.
29{
30public:
31 NullJournalSink() : Sink(severities::kDisabled, false)
32 {
33 }
34
35 ~NullJournalSink() override = default;
36
37 bool
39 {
40 return false;
41 }
42
43 bool
44 console() const override
45 {
46 return false;
47 }
48
49 void
50 console(bool) override
51 {
52 }
53
55 threshold() const override
56 {
58 }
59
60 void
62 {
63 }
64
65 void
67 {
68 }
69};
70
71//------------------------------------------------------------------------------
72
73Journal::Sink&
75{
76 static NullJournalSink sink;
77 return sink;
78}
79
80//------------------------------------------------------------------------------
81
82Journal::Sink::Sink(Severity thresh, bool console)
83 : thresh_(thresh), m_console(console)
84{
85}
86
87Journal::Sink::~Sink() = default;
88
89bool
91{
92 return level >= thresh_;
93}
94
95bool
97{
98 return m_console;
99}
100
101void
103{
104 m_console = output;
105}
106
109{
110 return thresh_;
111}
112
113void
115{
116 thresh_ = thresh;
117}
118
119//------------------------------------------------------------------------------
120
122 : m_sink(sink), m_level(level)
123{
124 // Modifiers applied from all ctors
126}
127
129 Stream const& stream,
130 std::ostream& manip(std::ostream&))
131 : ScopedStream(stream.sink(), stream.level())
132{
133 m_ostream << manip;
134}
135
137{
138 std::string const& s(m_ostream.str());
139 if (!s.empty())
140 {
141 if (s == "\n")
142 m_sink.write(m_level, "");
143 else
144 m_sink.write(m_level, s);
145 }
146}
147
150{
151 return m_ostream << manip;
152}
153
154//------------------------------------------------------------------------------
155
158{
159 return ScopedStream(*this, manip);
160}
161
162} // namespace beast
T boolalpha(T... args)
std::ostream & operator<<(std::ostream &manip(std::ostream &)) const
std::ostringstream m_ostream
Definition: Journal.h:174
ScopedStream(ScopedStream const &other)
Definition: Journal.h:141
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.
Provide a light-weight way to check active() before string formatting.
Definition: Journal.h:194
ScopedStream operator<<(std::ostream &manip(std::ostream &)) const
Output stream support.
Sink & sink() const
Returns the Sink associated with this Journal.
Definition: Journal.h:286
Stream stream(Severity level) const
Returns a stream for this sink, with the specified severity level.
Definition: Journal.h:293
static Sink & getNullSink()
Returns a Sink which does nothing.
Sink * m_sink
Definition: Journal.h:68
bool console() const override
Returns true if a message is also written to the Output Window (MSVC).
void threshold(severities::Severity) override
Set the minimum severity this sink will report.
~NullJournalSink() override=default
void console(bool) override
Set whether messages are also written to the Output Window (MSVC).
bool active(severities::Severity) const override
Returns true if text at the passed severity produces output.
void write(severities::Severity, std::string const &) override
Write text to the sink at the specified severity.
severities::Severity threshold() const override
Returns the minimum severity level this sink will report.
T empty(T... args)
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:31
T showbase(T... args)