xrpld
Loading...
Searching...
No Matches
beast_Journal.cpp
1#include <xrpl/beast/utility/Journal.h>
2
3#include <ios>
4#include <ostream>
5#include <string>
6
7namespace beast {
8
9//------------------------------------------------------------------------------
10
11// A Sink that does nothing.
13{
14public:
16 {
17 }
18
19 ~NullJournalSink() override = default;
20
21 [[nodiscard]] bool
22 active(Severity) const override
23 {
24 return false;
25 }
26
27 [[nodiscard]] bool
28 console() const override
29 {
30 return false;
31 }
32
33 void
34 console(bool) override
35 {
36 }
37
38 [[nodiscard]] Severity
39 threshold() const override
40 {
41 return Severity::Disabled;
42 }
43
44 void
46 {
47 }
48
49 void
50 write(Severity, std::string const&) override
51 {
52 }
53
54 void
56 {
57 }
58};
59
60//------------------------------------------------------------------------------
61
62Journal::Sink&
64{
65 static NullJournalSink kSink;
66 return kSink;
67}
68
69//------------------------------------------------------------------------------
70
72{
73}
74
75Journal::Sink::~Sink() = default;
76
77bool
79{
80 return level >= thresh_;
81}
82
83bool
85{
86 return console_;
87}
88
89void
91{
92 console_ = output;
93}
94
97{
98 return thresh_;
99}
100
101void
103{
104 thresh_ = thresh;
105}
106
107//------------------------------------------------------------------------------
108
110{
111 // Modifiers applied from all ctors
113}
114
120
122{
123 std::string const& s(ostream_.str());
124 if (!s.empty())
125 {
126 if (s == "\n")
127 {
128 sink_.write(level_, "");
129 }
130 else
131 {
132 sink_.write(level_, s);
133 }
134 }
135}
136
139{
140 return ostream_ << manip;
141}
142
143//------------------------------------------------------------------------------
144
147{
148 return ScopedStream(*this, manip);
149}
150
151} // namespace beast
T boolalpha(T... args)
std::ostream & operator<<(std::ostream &manip(std::ostream &)) const
std::ostringstream ostream_
Definition Journal.h:160
ScopedStream(ScopedStream const &other)
Definition Journal.h:128
Abstraction for the underlying message destination.
Definition Journal.h:51
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Sink(Sink const &sink)=default
virtual bool active(Severity level) const
Returns true if text at the passed severity produces output.
virtual bool console() const
Returns true if a message is also written to the Output Window (MSVC).
Provide a light-weight way to check active() before string formatting.
Definition Journal.h:176
ScopedStream operator<<(std::ostream &manip(std::ostream &)) const
Output stream support.
Sink & sink() const
Returns the Sink associated with this Journal.
Definition Journal.h:266
Stream stream(Severity level) const
Returns a stream for this sink, with the specified severity level.
Definition Journal.h:273
static Sink & getNullSink()
Returns a Sink which does nothing.
Severity threshold() const override
Returns the minimum severity level this sink will report.
bool console() const override
Returns true if a message is also written to the Output Window (MSVC).
bool active(Severity) const override
Returns true if text at the passed severity produces output.
void threshold(Severity) override
Set the minimum severity this sink will report.
void writeAlways(Severity, std::string const &) override
Bypass filter and write text to the sink at the specified severity.
~NullJournalSink() override=default
void console(bool) override
Set whether messages are also written to the Output Window (MSVC).
void write(Severity, std::string const &) override
Write text to the sink at the specified severity.
T empty(T... args)
Severity
Severity level / threshold of a Journal message.
Definition Journal.h:11
T showbase(T... args)