Files
bitcoin/src/test/util/logging.cpp
MarcoFalke fa5f297748 scripted-diff: [doc] Unify stale copyright headers
-BEGIN VERIFY SCRIPT-

 sed --in-place --regexp-extended \
   's;( 20[0-2][0-9])(-20[0-2][0-9])? The Bitcoin Core developers;\1-present The Bitcoin Core developers;g' \
   $( git grep -l 'The Bitcoin Core developers' -- ':(exclude)COPYING' ':(exclude)src/ipc/libmultiprocess' ':(exclude)src/minisketch' )

-END VERIFY SCRIPT-
2025-12-16 22:21:15 +01:00

34 lines
1006 B
C++

// Copyright (c) 2019-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/util/logging.h>
#include <logging.h>
#include <noui.h>
#include <tinyformat.h>
#include <cstdlib>
#include <iostream>
DebugLogHelper::DebugLogHelper(std::string message, MatchFn match)
: m_message{std::move(message)}, m_match(std::move(match))
{
m_print_connection = LogInstance().PushBackCallback(
[this](const std::string& s) {
if (m_found) return;
m_found = s.find(m_message) != std::string::npos && m_match(&s);
});
noui_test_redirect();
}
DebugLogHelper::~DebugLogHelper()
{
noui_reconnect();
LogInstance().DeleteCallback(m_print_connection);
if (!m_found && m_match(nullptr)) {
tfm::format(std::cerr, "Fatal error: expected message not found in the debug log: '%s'\n", m_message);
std::abort();
}
}