xrpld
Loading...
Searching...
No Matches
beast_Journal_test.cpp
1#include <xrpl/beast/unit_test/suite.h>
2#include <xrpl/beast/utility/Journal.h>
3
4#include <string>
5
6namespace beast {
7
9{
10public:
11 class TestSink : public Journal::Sink
12 {
13 private:
14 int count_{0};
15
16 public:
18 {
19 }
20
21 [[nodiscard]] int
22 count() const
23 {
24 return count_;
25 }
26
27 void
29 {
30 count_ = 0;
31 }
32
33 void
34 write(Severity level, std::string const&) override
35 {
36 if (level >= threshold())
37 ++count_;
38 }
39
40 void
41 writeAlways(Severity level, std::string const&) override
42 {
43 ++count_;
44 }
45 };
46
47 void
48 run() override
49 {
50 TestSink sink;
51
53
54 Journal const j(sink);
55
56 j.trace() << " ";
57 BEAST_EXPECT(sink.count() == 0);
58 j.debug() << " ";
59 BEAST_EXPECT(sink.count() == 0);
60 j.info() << " ";
61 BEAST_EXPECT(sink.count() == 1);
62 j.warn() << " ";
63 BEAST_EXPECT(sink.count() == 2);
64 j.error() << " ";
65 BEAST_EXPECT(sink.count() == 3);
66 j.fatal() << " ";
67 BEAST_EXPECT(sink.count() == 4);
68
69 sink.reset();
70
72
73 j.trace() << " ";
74 BEAST_EXPECT(sink.count() == 0);
75 j.debug() << " ";
76 BEAST_EXPECT(sink.count() == 1);
77 j.info() << " ";
78 BEAST_EXPECT(sink.count() == 2);
79 j.warn() << " ";
80 BEAST_EXPECT(sink.count() == 3);
81 j.error() << " ";
82 BEAST_EXPECT(sink.count() == 4);
83 j.fatal() << " ";
84 BEAST_EXPECT(sink.count() == 5);
85 }
86};
87
89
90} // namespace beast
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
void writeAlways(Severity level, std::string const &) override
Bypass filter and write text to the sink at the specified severity.
void write(Severity level, std::string const &) override
Write text to the sink at the specified severity.
void run() override
Runs the suite.
A generic endpoint for log messages.
Definition Journal.h:38
Stream fatal() const
Definition Journal.h:321
Stream error() const
Definition Journal.h:315
Stream debug() const
Definition Journal.h:297
Stream info() const
Definition Journal.h:303
Stream trace() const
Severity stream access functions.
Definition Journal.h:291
Stream warn() const
Definition Journal.h:309
A testsuite class.
Definition suite.h:50
Severity
Severity level / threshold of a Journal message.
Definition Journal.h:11
BEAST_DEFINE_TESTSUITE(aged_set, beast, beast)