rippled
CheckMessageLogs.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 Ripple Labs Inc.
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 <ripple/basics/Log.h>
21 
22 namespace ripple {
23 namespace test {
24 
27 class CheckMessageLogs : public Logs
28 {
30  bool* pFound_;
31 
33  {
35 
36  public:
39  CheckMessageLogs& owner)
40  : beast::Journal::Sink(threshold, false), owner_(owner)
41  {
42  }
43 
44  void
46  override
47  {
48  if (text.find(owner_.msg_) != std::string::npos)
49  *owner_.pFound_ = true;
50  }
51  };
52 
53 public:
60  CheckMessageLogs(std::string msg, bool* pFound)
61  : Logs{beast::severities::kDebug}, msg_{std::move(msg)}, pFound_{pFound}
62  {
63  }
64 
67  std::string const& partition,
69  {
70  return std::make_unique<CheckMessageSink>(threshold, *this);
71  }
72 };
73 
74 } // namespace test
75 } // namespace ripple
beast::Journal::Sink
Abstraction for the underlying message destination.
Definition: Journal.h:74
std::string
STL class.
ripple::Logs
Manages partitions for logging.
Definition: Log.h:48
ripple::test::CheckMessageLogs::CheckMessageSink::owner_
CheckMessageLogs & owner_
Definition: CheckMessageLogs.h:34
ripple::test::CheckMessageLogs::msg_
std::string msg_
Definition: CheckMessageLogs.h:29
std::string::find
T find(T... args)
ripple::test::CheckMessageLogs::CheckMessageSink
Definition: CheckMessageLogs.h:32
ripple::Logs::Sink
Definition: Log.h:51
ripple::test::CheckMessageLogs::CheckMessageSink::CheckMessageSink
CheckMessageSink(beast::severities::Severity threshold, CheckMessageLogs &owner)
Definition: CheckMessageLogs.h:37
ripple::test::CheckMessageLogs
Log manager that searches for a specific message substring.
Definition: CheckMessageLogs.h:27
ripple::Logs::threshold
beast::severities::Severity threshold() const
Definition: Log.cpp:150
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::CheckMessageLogs::makeSink
std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::severities::Severity threshold) override
Definition: CheckMessageLogs.h:66
beast::Journal::Sink::threshold
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Definition: beast_Journal.cpp:106
beast::severities::Severity
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:31
beast::severities::kDebug
@ kDebug
Definition: Journal.h:35
ripple::test::CheckMessageLogs::CheckMessageSink::write
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Definition: CheckMessageLogs.h:45
ripple::test::CheckMessageLogs::CheckMessageLogs
CheckMessageLogs(std::string msg, bool *pFound)
Constructor.
Definition: CheckMessageLogs.h:60
ripple::test::CheckMessageLogs::pFound_
bool * pFound_
Definition: CheckMessageLogs.h:30
std::unique_ptr< beast::Journal::Sink >
beast
Definition: base_uint.h:641