xrpld
Loading...
Searching...
No Matches
CaptureLogs.h
1#pragma once
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5
6#include <memory>
7#include <mutex>
8#include <sstream>
9#include <string>
10
11namespace xrpl::test {
12
19class CaptureLogs : public Logs
20{
24
29 {
32
33 public:
35 : beast::Journal::Sink(threshold, false), strmMutex_(mutex), strm_(strm)
36 {
37 }
38
39 void
40 write(beast::Severity level, std::string const& text) override
41 {
42 std::scoped_lock const lock(strmMutex_);
43 strm_ << text;
44 }
45
46 void
47 writeAlways(beast::Severity level, std::string const& text) override
48 {
49 std::scoped_lock const lock(strmMutex_);
50 strm_ << text;
51 }
52 };
53
54public:
55 explicit CaptureLogs(std::string* pResult) : Logs(beast::Severity::Info), pResult_(pResult)
56 {
57 }
58
59 ~CaptureLogs() override
60 {
61 *pResult_ = strm_.str();
62 }
63
69};
70
71} // namespace xrpl::test
Abstraction for the underlying message destination.
Definition Journal.h:59
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Sink(Sink const &sink)=default
beast::Severity threshold() const
Definition Log.cpp:143
Logs(beast::Severity level)
Definition Log.cpp:112
void writeAlways(beast::Severity level, std::string const &text) override
Bypass filter and write text to the sink at the specified severity.
Definition CaptureLogs.h:47
void write(beast::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Definition CaptureLogs.h:40
CaptureSink(beast::Severity threshold, std::mutex &mutex, std::stringstream &strm)
Definition CaptureLogs.h:34
std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::Severity threshold) override
Definition CaptureLogs.h:65
std::stringstream strm_
Definition CaptureLogs.h:22
std::string * pResult_
Definition CaptureLogs.h:23
CaptureLogs(std::string *pResult)
Definition CaptureLogs.h:55
T make_unique(T... args)
Severity
Severity level / threshold of a Journal message.
Definition Journal.h:16