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)
72 : thresh_(thresh), m_console(console)
73{
74}
75
76Journal::Sink::~Sink() = default;
77
78bool
80{
81 return level >= thresh_;
82}
83
84bool
86{
87 return m_console;
88}
89
90void
92{
93 m_console = output;
94}
95
98{
99 return thresh_;
100}
101
102void
104{
105 thresh_ = thresh;
106}
107
108//------------------------------------------------------------------------------
109
111 : m_sink(sink), m_level(level)
112{
113 // Modifiers applied from all ctors
115}
116
118 Stream const& stream,
119 std::ostream& manip(std::ostream&))
120 : ScopedStream(stream.sink(), stream.level())
121{
122 m_ostream << manip;
123}
124
126{
127 std::string const& s(m_ostream.str());
128 if (!s.empty())
129 {
130 if (s == "\n")
131 m_sink.write(m_level, "");
132 else
133 m_sink.write(m_level, s);
134 }
135}
136
139{
140 return m_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 m_ostream
Definition Journal.h:166
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:186
ScopedStream operator<<(std::ostream &manip(std::ostream &)) const
Output stream support.
Sink & sink() const
Returns the Sink associated with this Journal.
Definition Journal.h:278
Stream stream(Severity level) const
Returns a stream for this sink, with the specified severity level.
Definition Journal.h:285
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)