test: Replace DEBUG_LOG_OUT with -printtoconsole=1
What changed, and why it matters
This commit is a test-only cleanup. It removes a custom test logging hook called DEBUG_LOG_OUT and replaces it with Bitcoin Core's existing -printtoconsole=1 command-line option. There is no change to the production wallet, networking, consensus, or node code that ordinary users run.
No security action needed. Treat as ordinary test infrastructure maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes the global G_TEST_LOG_FUN callback and all sites that defined or registered it (bench, qt tests, fuzz, unit test main, setup_common). CTest invocations are switched from passing DEBUG_LOG_OUT to passing -printtoconsole=1. This is a refactoring of how test logs are emitted; it does not alter logging behavior available in bitcoind or the security boundary of the logger.
Changed components
src/test/main.cppsrc/test/util/setup_common.cppsrc/test/util/setup_common.hsrc/test/CMakeLists.txtsrc/test/fuzz/fuzz.cppsrc/qt/test/test_main.cppsrc/bench/bench.cppInspect captured patch +1 / −23
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
index 0b2ee6e3..45d1b360 100644
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -20,8 +20,6 @@
using namespace std::chrono_literals;
-const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
-
/**
* Retrieves the available test setup command line arguments that may be used
* in the benchmark. They will be used only if the benchmark utilizes a
diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp
index a8015fb5..5e91b072 100644
--- a/src/qt/test/test_main.cpp
+++ b/src/qt/test/test_main.cpp
@@ -28,8 +28,6 @@
#include <functional>
-const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
-
const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{};
const std::function<std::string()> G_TEST_GET_FULL_NAME{};
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index 7d9dccba..795e43e8 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -195,7 +195,7 @@ function(add_boost_test source_file)
list(REMOVE_ITEM test_suite_macro "mock_process")
foreach(test_suite_name IN LISTS test_suite_macro)
add_test(NAME ${test_suite_name}
- COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT
+ COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- -printtoconsole=1
)
set_property(TEST ${test_suite_name} PROPERTY
SKIP_REGULAR_EXPRESSION
diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp
index d4d82695..7fba26dd 100644
--- a/src/test/fuzz/fuzz.cpp
+++ b/src/test/fuzz/fuzz.cpp
@@ -37,8 +37,6 @@
__AFL_FUZZ_INIT();
#endif
-const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
-
/**
* A copy of the command line arguments that start with `--`.
* First `LLVMFuzzerInitialize()` is called, which saves the arguments to `g_args`.
diff --git a/src/test/main.cpp b/src/test/main.cpp
index 0b7c451a..398ab4d6 100644
--- a/src/test/main.cpp
+++ b/src/test/main.cpp
@@ -14,18 +14,6 @@
#include <functional>
#include <iostream>
-/** Redirect debug log to unit_test.log files */
-const std::function<void(const std::string&)> G_TEST_LOG_FUN = [](const std::string& s) {
- static const bool should_log{std::any_of(
- &boost::unit_test::framework::master_test_suite().argv[1],
- &boost::unit_test::framework::master_test_suite().argv[boost::unit_test::framework::master_test_suite().argc],
- [](const char* arg) {
- return std::string{"DEBUG_LOG_OUT"} == arg;
- })};
- if (!should_log) return;
- std::cout << s;
-};
-
/**
* Retrieve the command line arguments from boost.
* Allows usage like:
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index 6fdc9e18..8b746193 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -200,7 +200,6 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
gArgs.ForceSetArg("-datadir", fs::PathToString(m_path_root));
SelectParams(chainType);
- if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN);
InitLogging(*m_node.args);
AppInitParameterInteraction(*m_node.args);
LogInstance().StartLogging();
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index c02a4fd3..8b1b0632 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -35,9 +35,6 @@ class FastRandomContext;
class uint160;
class uint256;
-/** This is connected to the logger. Can be used to redirect logs to any other log */
-extern const std::function<void(const std::string&)> G_TEST_LOG_FUN;
-
/** Retrieve the command line arguments. */
extern const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.