diff --git a/src/logging.cpp b/src/logging.cpp index 4b6fd96b1ec..0dd760b95dc 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -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; } diff --git a/src/logging/categories.h b/src/logging/categories.h index dff00adaf1a..b4c6b1a196c 100644 --- a/src/logging/categories.h +++ b/src/logging/categories.h @@ -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 diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index 34ef8eb18dd..6d0d5511e33 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -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()) { diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp index 5595fe16de4..29cbe8e7df7 100644 --- a/src/test/logging_tests.cpp +++ b/src/test/logging_tests.cpp @@ -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 expected; diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 9e82eae8e66..830fca0ea9e 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -165,7 +165,6 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts) "-logthreadnames", "-loglevel=trace", "-debug", - "-debugexclude=libevent", "-debugexclude=leveldb", }, opts.extra_args); diff --git a/test/functional/rpc_misc.py b/test/functional/rpc_misc.py index 6e4c908d306..5cc3a29c463 100755 --- a/test/functional/rpc_misc.py +++ b/test/functional/rpc_misc.py @@ -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() diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 77a7fcb4c8b..a7c140a53bb 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -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