logging: deprecate libevent category

Creates logic to deprecate logging categories but still
"support" them so the software doesn't quit with unknown category
on startup. Deprecated categories are always false and attempts
to switch them are logged as warnings.
This commit is contained in:
Matthew Zipkin
2026-04-28 13:22:26 -04:00
parent 8c1eea0777
commit 39e9099da5
7 changed files with 31 additions and 16 deletions

View File

@@ -133,6 +133,11 @@ void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
bool BCLog::Logger::EnableCategory(std::string_view str)
{
if (const auto flag{GetLogCategory(str)}) {
if (*flag & DEPRECATED){
LogWarning("The logging category `%s` is deprecated, can not be enabled, and will be removed in a future version", str);
// Deprecated does not mean unsupported, which may prevent startup
return true;
}
EnableCategory(*flag);
return true;
}
@@ -147,6 +152,11 @@ void BCLog::Logger::DisableCategory(BCLog::LogFlags flag)
bool BCLog::Logger::DisableCategory(std::string_view str)
{
if (const auto flag{GetLogCategory(str)}) {
if (*flag & DEPRECATED){
LogWarning("The logging category `%s` is deprecated and will be removed in a future version", str);
// Deprecated does not mean unsupported, which may prevent startup
return true;
}
DisableCategory(*flag);
return true;
}

View File

@@ -46,9 +46,10 @@ enum LogFlags : CategoryMask {
TXPACKAGES = (CategoryMask{1} << 28),
KERNEL = (CategoryMask{1} << 29),
PRIVBROADCAST = (CategoryMask{1} << 30),
ALL = ~NONE,
DEPRECATED = LIBEVENT,
// Remove deprecated categories from ALL
ALL = ~DEPRECATED,
};
} // namespace BCLog
#endif // BITCOIN_LOGGING_CATEGORIES_H

View File

@@ -248,26 +248,16 @@ static RPCMethod logging()
},
RPCExamples{
HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
+ HelpExampleRpc("logging", "[\"all\"], [\"libevent\"]")
+ HelpExampleRpc("logging", "[\"all\"], [\"leveldb\"]")
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
BCLog::CategoryMask original_log_categories = LogInstance().GetCategoryMask();
if (request.params[0].isArray()) {
EnableOrDisableLogCategories(request.params[0], true);
}
if (request.params[1].isArray()) {
EnableOrDisableLogCategories(request.params[1], false);
}
BCLog::CategoryMask updated_log_categories = LogInstance().GetCategoryMask();
BCLog::CategoryMask changed_log_categories = original_log_categories ^ updated_log_categories;
// Update libevent logging if BCLog::LIBEVENT has changed.
if (changed_log_categories & BCLog::LIBEVENT) {
// Currently no modules in the codebase produce libevent log messages.
// To redirect libevent messages to our own logs see commit 8b2d6edaa9fbfb6344ca51edd0b3655b451cbcac
// in https://github.com/bitcoin/bitcoin/pull/6695
}
UniValue result(UniValue::VOBJ);
for (const auto& logCatActive : LogInstance().LogCategoriesList()) {

View File

@@ -167,7 +167,11 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros_CategoryName, LogSetup)
for (const auto& category_name : category_names) {
const auto trimmed_category_name = TrimString(category_name);
const auto category{*Assert(BCLog::Logger::GetLogCategory(trimmed_category_name))};
expected_category_names.emplace_back(category, trimmed_category_name);
if (category & BCLog::LogFlags::ALL) {
expected_category_names.emplace_back(category, trimmed_category_name);
} else {
BOOST_CHECK(category & BCLog::LogFlags::DEPRECATED);
}
}
std::vector<std::string> expected;

View File

@@ -165,7 +165,6 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
"-logthreadnames",
"-loglevel=trace",
"-debug",
"-debugexclude=libevent",
"-debugexclude=leveldb",
},
opts.extra_args);

View File

@@ -120,6 +120,18 @@ class RpcMiscTest(BitcoinTestFramework):
# Specifying an unknown index name returns an empty result
assert_equal(node.getindexinfo("foo"), {})
# Test a deprecated category
node.logging(include=['all'])
for category, value in node.logging().items():
# Everything True except one...
assert_equal(value, category != "libevent")
with self.nodes[0].assert_debug_log(["The logging category `libevent` is deprecated"]):
node.logging(include=['libevent'])
assert_equal(node.logging()['libevent'], False)
with self.nodes[0].assert_debug_log(["The logging category `libevent` is deprecated"]):
node.logging(exclude=['libevent'])
assert_equal(node.logging()['libevent'], False)
if __name__ == '__main__':
RpcMiscTest(__file__).main()

View File

@@ -142,7 +142,6 @@ class TestNode():
f"-datadir={self.datadir_path}",
"-logtimemicros",
"-debug",
"-debugexclude=libevent",
"-debugexclude=leveldb",
"-debugexclude=rand",
"-uacomment=testnode%d" % i, # required for subversion uniqueness across peers