rippled
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:
15 NullJournalSink() : Sink(severities::kDisabled, false)
16 {
17 }
18
19 ~NullJournalSink() override = default;
20
21 bool
23 {
24 return false;
25 }
26
27 bool
28 console() const override
29 {
30 return false;
31 }
32
33 void
34 console(bool) override
35 {
36 }
37
39 threshold() const override
40 {
42 }
43
44 void
46 {
47 }
48
49 void
51 {
52 }
53
54 void
56 {
57 }
58};
59
60//------------------------------------------------------------------------------
61
62Journal::Sink&
64{
65 static NullJournalSink sink;
66 return sink;
67}
68
69//------------------------------------------------------------------------------
70
71Journal::Sink::Sink(Severity thresh, bool console) : thresh_(thresh), m_console(console)
72{
73}
74
75Journal::Sink::~Sink() = default;
76
77bool
79{
80 return level >= thresh_;
81}
82
83bool
85{
86 return m_console;
87}
88
89void
91{
92 m_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(m_ostream.str());
124 if (!s.empty())
125 {
126 if (s == "\n")
127 m_sink.write(m_level, "");
128 else
129 m_sink.write(m_level, s);
130 }
131}
132
135{
136 return m_ostream << manip;
137}
138
139//------------------------------------------------------------------------------
140
143{
144 return ScopedStream(*this, manip);
145}
146
147} // namespace beast
T boolalpha(T... args)
std::ostream & operator<<(std::ostream &manip(std::ostream &)) const
std::ostringstream m_ostream
Definition Journal.h:165
ScopedStream(ScopedStream const &other)
Definition Journal.h:133
Abstraction for the underlying message destination.
Definition Journal.h:57
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:181
ScopedStream operator<<(std::ostream &manip(std::ostream &)) const
Output stream support.
Sink & sink() const
Returns the Sink associated with this Journal.
Definition Journal.h:270
Stream stream(Severity level) const
Returns a stream for this sink, with the specified severity level.
Definition Journal.h:277
static Sink & getNullSink()
Returns a Sink which does nothing.
Sink * m_sink
Definition Journal.h:50
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:13
T showbase(T... args)