rippled
Loading...
Searching...
No Matches
beast_Journal_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/beast/unit_test.h>
21#include <xrpl/beast/utility/Journal.h>
22
23namespace beast {
24
26{
27public:
28 class TestSink : public Journal::Sink
29 {
30 private:
32
33 public:
34 TestSink() : Sink(severities::kWarning, false), m_count(0)
35 {
36 }
37
38 int
39 count() const
40 {
41 return m_count;
42 }
43
44 void
46 {
47 m_count = 0;
48 }
49
50 void
51 write(severities::Severity level, std::string const&) override
52 {
53 if (level >= threshold())
54 ++m_count;
55 }
56
57 void
59 {
60 ++m_count;
61 }
62 };
63
64 void
65 run() override
66 {
67 TestSink sink;
68
69 using namespace beast::severities;
70 sink.threshold(kInfo);
71
72 Journal j(sink);
73
74 j.trace() << " ";
75 BEAST_EXPECT(sink.count() == 0);
76 j.debug() << " ";
77 BEAST_EXPECT(sink.count() == 0);
78 j.info() << " ";
79 BEAST_EXPECT(sink.count() == 1);
80 j.warn() << " ";
81 BEAST_EXPECT(sink.count() == 2);
82 j.error() << " ";
83 BEAST_EXPECT(sink.count() == 3);
84 j.fatal() << " ";
85 BEAST_EXPECT(sink.count() == 4);
86
87 sink.reset();
88
89 sink.threshold(kDebug);
90
91 j.trace() << " ";
92 BEAST_EXPECT(sink.count() == 0);
93 j.debug() << " ";
94 BEAST_EXPECT(sink.count() == 1);
95 j.info() << " ";
96 BEAST_EXPECT(sink.count() == 2);
97 j.warn() << " ";
98 BEAST_EXPECT(sink.count() == 3);
99 j.error() << " ";
100 BEAST_EXPECT(sink.count() == 4);
101 j.fatal() << " ";
102 BEAST_EXPECT(sink.count() == 5);
103 }
104};
105
106BEAST_DEFINE_TESTSUITE(Journal, beast, beast);
107
108} // namespace beast
Abstraction for the underlying message destination.
Definition Journal.h:76
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:60
Stream fatal() const
Definition Journal.h:352
Stream error() const
Definition Journal.h:346
Stream debug() const
Definition Journal.h:328
Stream info() const
Definition Journal.h:334
Stream trace() const
Severity stream access functions.
Definition Journal.h:322
Stream warn() const
Definition Journal.h:340
A testsuite class.
Definition suite.h:55
A namespace for easy access to logging severity values.
Definition Journal.h:30
Severity
Severity level / threshold of a Journal message.
Definition Journal.h:32