From 611878b46f702f1844e4c89b7fd36a9a54e09167 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 11 Feb 2026 09:42:45 +1000 Subject: [PATCH] scripted-diff: logging: Drop LogAcceptCategory -BEGIN VERIFY SCRIPT- sed -i 's/LogAcceptCategory(\(.*\), [a-zA-Z:]*::Level::Debug)/util::log::ShouldDebugLog(\1)/g' $(git grep -l LogAcceptCategory -- '*.cpp') sed -i 's/LogAcceptCategory(\(.*\), [a-zA-Z:]*::Level::Trace)/util::log::ShouldTraceLog(\1)/g' $(git grep -l LogAcceptCategory -- '*.cpp') sed -i '/Return true if log accepts specified category/,/^$/d' src/logging.h -END VERIFY SCRIPT- --- src/blockencodings.cpp | 2 +- src/dbwrapper.cpp | 4 ++-- src/ipc/capnp/protocol.cpp | 4 ++-- src/logging.h | 6 ------ src/net_processing.cpp | 2 +- src/wallet/coinselection.cpp | 2 +- src/wallet/sqlite.cpp | 2 +- 7 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp index 18799cd8083..064e0853748 100644 --- a/src/blockencodings.cpp +++ b/src/blockencodings.cpp @@ -219,7 +219,7 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector< return READ_STATUS_FAILED; // Possible Short ID collision } - if (LogAcceptCategory(BCLog::CMPCTBLOCK, BCLog::Level::Debug)) { + if (util::log::ShouldDebugLog(BCLog::CMPCTBLOCK)) { const uint256 hash{block.GetHash()}; uint32_t tx_missing_size{0}; for (const auto& tx : vtx_missing) tx_missing_size += tx->ComputeTotalSize(); diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 3212f6d3701..fde8e8e44f8 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -59,7 +59,7 @@ public: // This code is adapted from posix_logger.h, which is why it is using vsprintf. // Please do not do this in normal code void Logv(const char * format, va_list ap) override { - if (!LogAcceptCategory(BCLog::LEVELDB, util::log::Level::Debug)) { + if (!util::log::ShouldDebugLog(BCLog::LEVELDB)) { return; } char buffer[500]; @@ -278,7 +278,7 @@ CDBWrapper::~CDBWrapper() void CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync) { - const bool log_memory = LogAcceptCategory(BCLog::LEVELDB, util::log::Level::Debug); + const bool log_memory = util::log::ShouldDebugLog(BCLog::LEVELDB); double mem_before = 0; if (log_memory) { mem_before = DynamicMemoryUsage() / double(1_MiB); diff --git a/src/ipc/capnp/protocol.cpp b/src/ipc/capnp/protocol.cpp index 2645e46f70f..e68ce872fba 100644 --- a/src/ipc/capnp/protocol.cpp +++ b/src/ipc/capnp/protocol.cpp @@ -33,8 +33,8 @@ namespace { mp::Log GetRequestedIPCLogLevel() { - if (LogAcceptCategory(BCLog::IPC, BCLog::Level::Trace)) return mp::Log::Trace; - if (LogAcceptCategory(BCLog::IPC, BCLog::Level::Debug)) return mp::Log::Debug; + if (util::log::ShouldTraceLog(BCLog::IPC)) return mp::Log::Trace; + if (util::log::ShouldDebugLog(BCLog::IPC)) return mp::Log::Debug; // Info, Warning, and Error are logged unconditionally return mp::Log::Info; diff --git a/src/logging.h b/src/logging.h index a727dc249d1..4bdcd0f241d 100644 --- a/src/logging.h +++ b/src/logging.h @@ -283,10 +283,4 @@ namespace BCLog { BCLog::Logger& LogInstance(); -/** Return true if log accepts specified category, at the specified level. */ -static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level) -{ - return LogInstance().WillLogCategoryLevel(category, level); -} - #endif // BITCOIN_LOGGING_H diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 6d35db931a5..94861130262 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2607,7 +2607,7 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlo resp.txn[i] = block.vtx[req.indexes[i]]; } - if (LogAcceptCategory(BCLog::CMPCTBLOCK, BCLog::Level::Debug)) { + if (util::log::ShouldDebugLog(BCLog::CMPCTBLOCK)) { uint32_t tx_requested_size{0}; for (const auto& tx : resp.txn) tx_requested_size += tx->ComputeTotalSize(); LogDebug(BCLog::CMPCTBLOCK, "Peer %d sent us a GETBLOCKTXN for block %s, sending a BLOCKTXN with %u txns. (%u bytes)\n", pfrom.GetId(), block.GetHash().ToString(), resp.txn.size(), tx_requested_size); diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index d6ea6851e64..1d9db426f6b 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -732,7 +732,7 @@ util::Result KnapsackSolver(std::vector& groups, c result.AddInput(*lowest_larger); } - if (LogAcceptCategory(BCLog::SELECTCOINS, BCLog::Level::Debug)) { + if (util::log::ShouldDebugLog(BCLog::SELECTCOINS)) { std::string log_message{"Coin selection best subset: "}; for (unsigned int i = 0; i < applicable_groups.size(); i++) { if (vfBest[i]) { diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp index 3d6583bb037..03adc7ec95e 100644 --- a/src/wallet/sqlite.cpp +++ b/src/wallet/sqlite.cpp @@ -267,7 +267,7 @@ void SQLiteDatabase::Open(int additional_flags) throw std::runtime_error(strprintf("SQLiteDatabase: Failed to enable extended result codes: %s\n", sqlite3_errstr(ret))); } // Trace SQL statements if tracing is enabled with -debug=walletdb -loglevel=walletdb:trace - if (LogAcceptCategory(BCLog::WALLETDB, BCLog::Level::Trace)) { + if (util::log::ShouldTraceLog(BCLog::WALLETDB)) { ret = sqlite3_trace_v2(m_db, SQLITE_TRACE_STMT, TraceSqlCallback, this); if (ret != SQLITE_OK) { LogWarning("Failed to enable SQL tracing for %s", Filename());