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 void
72 {
73 }
74};
75
76//------------------------------------------------------------------------------
77
78Journal::Sink&
80{
81 static NullJournalSink sink;
82 return sink;
83}
84
85//------------------------------------------------------------------------------
86
87Journal::Sink::Sink(Severity thresh, bool console)
88 : thresh_(thresh), m_console(console)
89{
90}
91
92Journal::Sink::~Sink() = default;
93
94bool
96{
97 return level >= thresh_;
98}
99
100bool
102{
103 return m_console;
104}
105
106void
108{
109 m_console = output;
110}
111
114{
115 return thresh_;
116}
117
118void
120{
121 thresh_ = thresh;
122}
123
124//------------------------------------------------------------------------------
125
127 : m_sink(sink), m_level(level)
128{
129 // Modifiers applied from all ctors
131}
132
134 Stream const& stream,
135 std::ostream& manip(std::ostream&))
136 : ScopedStream(stream.sink(), stream.level())
137{
138 m_ostream << manip;
139}
140
142{
143 std::string const& s(m_ostream.str());
144 if (!s.empty())
145 {
146 if (s == "\n")
147 m_sink.write(m_level, "");
148 else
149 m_sink.write(m_level, s);
150 }
151}
152
155{
156 return m_ostream << manip;
157}
158
159//------------------------------------------------------------------------------
160
163{
164 return ScopedStream(*this, manip);
165}
166
167} // namespace beast
T boolalpha(T... args)
std::ostream & operator<<(std::ostream &manip(std::ostream &)) const
std::ostringstream m_ostream
Definition: Journal.h:184
ScopedStream(ScopedStream const &other)
Definition: Journal.h:151
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:204
ScopedStream operator<<(std::ostream &manip(std::ostream &)) const
Output stream support.
Sink & sink() const
Returns the Sink associated with this Journal.
Definition: Journal.h:296
Stream stream(Severity level) const
Returns a stream for this sink, with the specified severity level.
Definition: Journal.h:303
static Sink & getNullSink()
Returns a Sink which does nothing.
Sink * m_sink
Definition: Journal.h:68
void writeAlways(severities::Severity, std::string const &) override
Bypass filter and write text to the sink at the specified severity.
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)