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
22#include <ios>
23#include <ostream>
24#include <string>
25
26namespace beast {
27
28//------------------------------------------------------------------------------
29
30// A Sink that does nothing.
32{
33public:
34 NullJournalSink() : Sink(severities::kDisabled, false)
35 {
36 }
37
38 ~NullJournalSink() override = default;
39
40 bool
42 {
43 return false;
44 }
45
46 bool
47 console() const override
48 {
49 return false;
50 }
51
52 void
53 console(bool) override
54 {
55 }
56
58 threshold() const override
59 {
61 }
62
63 void
65 {
66 }
67
68 void
70 {
71 }
72
73 void
75 {
76 }
77};
78
79//------------------------------------------------------------------------------
80
81Journal::Sink&
83{
84 static NullJournalSink sink;
85 return sink;
86}
87
88//------------------------------------------------------------------------------
89
90Journal::Sink::Sink(Severity thresh, bool console)
91 : thresh_(thresh), m_console(console)
92{
93}
94
95Journal::Sink::~Sink() = default;
96
97bool
99{
100 return level >= thresh_;
101}
102
103bool
105{
106 return m_console;
107}
108
109void
111{
112 m_console = output;
113}
114
117{
118 return thresh_;
119}
120
121void
123{
124 thresh_ = thresh;
125}
126
127//------------------------------------------------------------------------------
128
130 : m_sink(sink), m_level(level)
131{
132 // Modifiers applied from all ctors
134}
135
137 Stream const& stream,
138 std::ostream& manip(std::ostream&))
139 : ScopedStream(stream.sink(), stream.level())
140{
141 m_ostream << manip;
142}
143
145{
146 std::string const& s(m_ostream.str());
147 if (!s.empty())
148 {
149 if (s == "\n")
150 m_sink.write(m_level, "");
151 else
152 m_sink.write(m_level, s);
153 }
154}
155
158{
159 return m_ostream << manip;
160}
161
162//------------------------------------------------------------------------------
163
166{
167 return ScopedStream(*this, manip);
168}
169
170} // namespace beast
T boolalpha(T... args)
std::ostream & operator<<(std::ostream &manip(std::ostream &)) const
std::ostringstream m_ostream
Definition: Journal.h:185
ScopedStream(ScopedStream const &other)
Definition: Journal.h:152
Abstraction for the underlying message destination.
Definition: Journal.h:76
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:205
ScopedStream operator<<(std::ostream &manip(std::ostream &)) const
Output stream support.
Sink & sink() const
Returns the Sink associated with this Journal.
Definition: Journal.h:297
Stream stream(Severity level) const
Returns a stream for this sink, with the specified severity level.
Definition: Journal.h:304
static Sink & getNullSink()
Returns a Sink which does nothing.
Sink * m_sink
Definition: Journal.h:69
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:32
T showbase(T... args)