Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
util
logging.cpp
Go to the documentation of this file.
1
// Copyright (c) 2019-present 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 <cstdlib>
12
#include <iostream>
13
14
DebugLogHelper::DebugLogHelper
(std::string message,
MatchFn
match)
15
:
m_message
{
std
::move(message)},
m_match
(
std
::move(match))
16
{
17
m_print_connection
=
LogInstance
().
PushBackCallback
(
18
[
this
](
const
std::string& s) {
19
if
(
m_found
)
return
;
20
m_found
= s.find(
m_message
) != std::string::npos &&
m_match
(&s);
21
});
22
noui_test_redirect
();
23
}
24
25
DebugLogHelper::~DebugLogHelper
()
26
{
27
noui_reconnect
();
28
LogInstance
().
DeleteCallback
(
m_print_connection
);
29
if
(!
m_found
&&
m_match
(
nullptr
)) {
30
tfm::format
(std::cerr,
"Fatal error: expected message not found in the debug log: '%s'\n"
,
m_message
);
31
std::abort();
32
}
33
}
BCLog::Logger::PushBackCallback
std::list< std::function< void(conststd::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Connect a slot to the print signal and return the connection.
Definition
logging.h:200
BCLog::Logger::DeleteCallback
void DeleteCallback(std::list< std::function< void(const std::string &)> >::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Delete a connection.
Definition
logging.h:208
DebugLogHelper::m_print_connection
std::list< std::function< void(conststd::string &)> >::iterator m_print_connection
Definition
logging.h:38
DebugLogHelper::MatchFn
std::function< bool(const std::string *line)> MatchFn
Definition
logging.h:26
DebugLogHelper::m_match
MatchFn m_match
Definition
logging.h:39
DebugLogHelper::~DebugLogHelper
~DebugLogHelper()
Definition
logging.cpp:25
DebugLogHelper::DebugLogHelper
DebugLogHelper(std::string message, MatchFn match=[](const std::string *){ return true;})
Definition
logging.cpp:14
DebugLogHelper::m_message
const std::string m_message
Definition
logging.h:36
DebugLogHelper::m_found
bool m_found
Definition
logging.h:37
LogInstance
BCLog::Logger & LogInstance()
Definition
logging.cpp:26
std
Definition
common.h:29
tinyformat::format
void format(std::ostream &out, FormatStringCheck< sizeof...(Args)> fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition
tinyformat.h:1079
noui_test_redirect
void noui_test_redirect()
Redirect all bitcoind signal handlers to LogInfo.
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
noui.h
logging.h
tinyformat.h
Generated on
for Bitcoin Core by
1.17.0