Bitcoin Core  22.99.0
P2P Digital Currency
logging.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <test/util/logging.h>
6 
7 #include <logging.h>
8 #include <noui.h>
9 #include <tinyformat.h>
10 
11 #include <stdexcept>
12 
13 DebugLogHelper::DebugLogHelper(std::string message, MatchFn match)
14  : m_message{std::move(message)}, m_match(std::move(match))
15 {
16  m_print_connection = LogInstance().PushBackCallback(
17  [this](const std::string& s) {
18  if (m_found) return;
19  m_found = s.find(m_message) != std::string::npos && m_match(&s);
20  });
22 }
23 
25 {
28  if (!m_found && m_match(nullptr)) {
29  throw std::runtime_error(strprintf("'%s' not found in debug log\n", m_message));
30  }
31 }
BCLog::Logger::DeleteCallback
void DeleteCallback(std::list< std::function< void(const std::string &)>>::iterator it)
Delete a connection.
Definition: logging.h:121
DebugLogHelper::m_print_connection
std::list< std::function< void(const std::string &)> >::iterator m_print_connection
Definition: logging.h:18
DebugLogHelper::m_message
const std::string m_message
Definition: logging.h:16
DebugLogHelper::DebugLogHelper
DebugLogHelper(std::string message, MatchFn match=[](const std::string *){ return true;})
Definition: logging.cpp:13
DebugLogHelper::m_match
MatchFn m_match
Definition: logging.h:30
tinyformat.h
logging.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
DebugLogHelper::m_found
bool m_found
Definition: logging.h:17
DebugLogHelper::check_found
void check_found()
Definition: logging.cpp:24
DebugLogHelper::MatchFn
std::function< bool(const std::string *line)> MatchFn
Custom match checking function.
Definition: logging.h:29
LogInstance
BCLog::Logger & LogInstance()
Definition: logging.cpp:17
BCLog::Logger::PushBackCallback
std::list< std::function< void(const std::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun)
Connect a slot to the print signal and return the connection.
Definition: logging.h:113
noui.h
noui_test_redirect
void noui_test_redirect()
Redirect all bitcoind signal handlers to LogPrintf.
Definition: noui.cpp:83
noui_reconnect
void noui_reconnect()
Reconnects the regular Non-GUI handlers after having used noui_test_redirect.
Definition: noui.cpp:93