rippled
Loading...
Searching...
No Matches
beast_Journal_test.cpp
1#include <xrpl/beast/unit_test.h>
2#include <xrpl/beast/utility/Journal.h>
3
4namespace beast {
5
7{
8public:
9 class TestSink : public Journal::Sink
10 {
11 private:
13
14 public:
15 TestSink() : Sink(severities::kWarning, false), m_count(0)
16 {
17 }
18
19 int
20 count() const
21 {
22 return m_count;
23 }
24
25 void
27 {
28 m_count = 0;
29 }
30
31 void
32 write(severities::Severity level, std::string const&) override
33 {
34 if (level >= threshold())
35 ++m_count;
36 }
37
38 void
40 {
41 ++m_count;
42 }
43 };
44
45 void
46 run() override
47 {
48 TestSink sink;
49
50 using namespace beast::severities;
51 sink.threshold(kInfo);
52
53 Journal j(sink);
54
55 j.trace() << " ";
56 BEAST_EXPECT(sink.count() == 0);
57 j.debug() << " ";
58 BEAST_EXPECT(sink.count() == 0);
59 j.info() << " ";
60 BEAST_EXPECT(sink.count() == 1);
61 j.warn() << " ";
62 BEAST_EXPECT(sink.count() == 2);
63 j.error() << " ";
64 BEAST_EXPECT(sink.count() == 3);
65 j.fatal() << " ";
66 BEAST_EXPECT(sink.count() == 4);
67
68 sink.reset();
69
70 sink.threshold(kDebug);
71
72 j.trace() << " ";
73 BEAST_EXPECT(sink.count() == 0);
74 j.debug() << " ";
75 BEAST_EXPECT(sink.count() == 1);
76 j.info() << " ";
77 BEAST_EXPECT(sink.count() == 2);
78 j.warn() << " ";
79 BEAST_EXPECT(sink.count() == 3);
80 j.error() << " ";
81 BEAST_EXPECT(sink.count() == 4);
82 j.fatal() << " ";
83 BEAST_EXPECT(sink.count() == 5);
84 }
85};
86
87BEAST_DEFINE_TESTSUITE(Journal, beast, beast);
88
89} // namespace beast
Abstraction for the underlying message destination.
Definition Journal.h:57
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
void write(severities::Severity level, std::string const &) override
Write text to the sink at the specified severity.
void writeAlways(severities::Severity level, std::string const &) override
Bypass filter and write text to the sink at the specified severity.
void run() override
Runs the suite.
A generic endpoint for log messages.
Definition Journal.h:41
Stream fatal() const
Definition Journal.h:333
Stream error() const
Definition Journal.h:327
Stream debug() const
Definition Journal.h:309
Stream info() const
Definition Journal.h:315
Stream trace() const
Severity stream access functions.
Definition Journal.h:303
Stream warn() const
Definition Journal.h:321
A testsuite class.
Definition suite.h:52
A namespace for easy access to logging severity values.
Definition Journal.h:11
Severity
Severity level / threshold of a Journal message.
Definition Journal.h:13