xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
helpers
CaptureSink.h
1
#pragma once
2
3
#include <xrpl/beast/utility/Journal.h>
4
5
#include <
mutex
>
6
#include <
sstream
>
7
#include <
string
>
8
9
namespace
xrpl::test
{
10
11
class
CaptureSink
:
public
beast::Journal::Sink
12
{
13
mutable
std::mutex
mutex_
;
14
std::stringstream
strm_
;
15
16
public
:
17
explicit
CaptureSink
(
beast::Severity
threshold
=
beast::Severity::Debug
)
18
:
Sink
{
threshold
, false}
19
{
20
}
21
22
void
23
write
(
beast::Severity
level,
std::string
const
& text)
override
24
{
25
if
(level <
threshold
())
26
return
;
27
writeAlways
(level, text);
28
}
29
30
void
31
writeAlways
(
beast::Severity
/*level*/
,
std::string
const
& text)
override
32
{
33
// Journal sinks may be written to concurrently (e.g. from a backend's background workers),
34
// so serialize access to strm_. write() funnels into writeAlways(), so the lock lives here
35
// only: locking in both would self-deadlock on this non-recursive mutex.
36
std::scoped_lock
const
lock(
mutex_
);
37
strm_
<< text <<
'\n'
;
38
}
39
40
[[nodiscard]]
std::string
41
messages
()
const
42
{
43
// Returns a snapshot of the captured output. Takes the lock so the read is safe even if a
44
// writer is still active.
45
std::scoped_lock
const
lock(
mutex_
);
46
return
strm_
.str();
47
}
48
};
49
50
}
// namespace xrpl::test
std::string
std::stringstream
beast::Journal::Sink
Abstraction for the underlying message destination.
Definition
Journal.h:59
beast::Journal::Sink::threshold
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Definition
beast_Journal.cpp:96
beast::Journal::Sink::Sink
Sink(Sink const &sink)=default
xrpl::test::CaptureSink::writeAlways
void writeAlways(beast::Severity, std::string const &text) override
Bypass filter and write text to the sink at the specified severity.
Definition
CaptureSink.h:31
xrpl::test::CaptureSink::CaptureSink
CaptureSink(beast::Severity threshold=beast::Severity::Debug)
Definition
CaptureSink.h:17
xrpl::test::CaptureSink::write
void write(beast::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Definition
CaptureSink.h:23
xrpl::test::CaptureSink::strm_
std::stringstream strm_
Definition
CaptureSink.h:14
xrpl::test::CaptureSink::messages
std::string messages() const
Definition
CaptureSink.h:41
xrpl::test::CaptureSink::mutex_
std::mutex mutex_
Definition
CaptureSink.h:13
mutex
beast::Severity
Severity
Severity level / threshold of a Journal message.
Definition
Journal.h:16
beast::Severity::Debug
@ Debug
Definition
Journal.h:20
xrpl::test
Definition
STLedgerEntry.h:21
std::scoped_lock
sstream
string
Generated by
1.17.0