From f64b861c0940ca90869303a9754ebe5bf40bb0c7 Mon Sep 17 00:00:00 2001 From: Larry Ruane Date: Thu, 1 Dec 2022 09:02:50 -0700 Subject: [PATCH] log: expand BCLog::LogFlags (categories) to 64 bits This will increase the maximum number of logging categories from 32 to 64. --- src/interfaces/node.h | 3 +- src/logging.h | 70 +++++++++++++++++++++-------------------- src/node/interfaces.cpp | 2 +- src/rpc/node.cpp | 6 ++-- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 81844c61856fa..b87c78db521b9 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -7,6 +7,7 @@ #include #include // For CAmount +#include // For BCLog::CategoryMask #include // For NodeId #include // For banmap_t #include // For Network @@ -84,7 +85,7 @@ class Node virtual int getExitStatus() = 0; // Get log flags. - virtual uint32_t getLogCategories() = 0; + virtual BCLog::CategoryMask getLogCategories() = 0; //! Initialize app dependencies. virtual bool baseInitialize() = 0; diff --git a/src/logging.h b/src/logging.h index 2ff58979cb3d8..d630c30800efd 100644 --- a/src/logging.h +++ b/src/logging.h @@ -37,40 +37,42 @@ struct LogCategory { }; namespace BCLog { - enum LogFlags : uint32_t { - NONE = 0, - NET = (1 << 0), - TOR = (1 << 1), - MEMPOOL = (1 << 2), - HTTP = (1 << 3), - BENCH = (1 << 4), - ZMQ = (1 << 5), - WALLETDB = (1 << 6), - RPC = (1 << 7), - ESTIMATEFEE = (1 << 8), - ADDRMAN = (1 << 9), - SELECTCOINS = (1 << 10), - REINDEX = (1 << 11), - CMPCTBLOCK = (1 << 12), - RAND = (1 << 13), - PRUNE = (1 << 14), - PROXY = (1 << 15), - MEMPOOLREJ = (1 << 16), - LIBEVENT = (1 << 17), - COINDB = (1 << 18), - QT = (1 << 19), - LEVELDB = (1 << 20), - VALIDATION = (1 << 21), - I2P = (1 << 22), - IPC = (1 << 23), + using CategoryMask = uint64_t; + constexpr CategoryMask mask_bit{1}; + enum LogFlags : CategoryMask { + NONE = CategoryMask{0}, + NET = (mask_bit << 0), + TOR = (mask_bit << 1), + MEMPOOL = (mask_bit << 2), + HTTP = (mask_bit << 3), + BENCH = (mask_bit << 4), + ZMQ = (mask_bit << 5), + WALLETDB = (mask_bit << 6), + RPC = (mask_bit << 7), + ESTIMATEFEE = (mask_bit << 8), + ADDRMAN = (mask_bit << 9), + SELECTCOINS = (mask_bit << 10), + REINDEX = (mask_bit << 11), + CMPCTBLOCK = (mask_bit << 12), + RAND = (mask_bit << 13), + PRUNE = (mask_bit << 14), + PROXY = (mask_bit << 15), + MEMPOOLREJ = (mask_bit << 16), + LIBEVENT = (mask_bit << 17), + COINDB = (mask_bit << 18), + QT = (mask_bit << 19), + LEVELDB = (mask_bit << 20), + VALIDATION = (mask_bit << 21), + I2P = (mask_bit << 22), + IPC = (mask_bit << 23), #ifdef DEBUG_LOCKCONTENTION - LOCK = (1 << 24), + LOCK = (mask_bit << 24), #endif - BLOCKSTORAGE = (1 << 25), - TXRECONCILIATION = (1 << 26), - SCAN = (1 << 27), - TXPACKAGES = (1 << 28), - ALL = ~(uint32_t)0, + BLOCKSTORAGE = (mask_bit << 25), + TXRECONCILIATION = (mask_bit << 26), + SCAN = (mask_bit << 27), + TXPACKAGES = (mask_bit << 28), + ALL = ~NONE, }; enum class Level { Trace = 0, // High-volume or detailed logging for development/debugging @@ -119,7 +121,7 @@ namespace BCLog { std::atomic m_log_level{DEFAULT_LOG_LEVEL}; /** Log categories bitfield. */ - std::atomic m_categories{BCLog::NONE}; + std::atomic m_categories{BCLog::NONE}; void FormatLogStrInPlace(std::string& str, LogFlags category, Level level, std::string_view source_file, int source_line, std::string_view logging_function, std::string_view threadname, SystemClock::time_point now, std::chrono::seconds mocktime) const; @@ -204,7 +206,7 @@ namespace BCLog { void SetLogLevel(Level level) { m_log_level = level; } bool SetLogLevel(std::string_view level); - uint32_t GetCategoryMask() const { return m_categories.load(); } + CategoryMask GetCategoryMask() const { return m_categories.load(); } void EnableCategory(LogFlags flag); bool EnableCategory(std::string_view str); diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 9fe08eb3dd3d4..d8d1a7421717e 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -100,7 +100,7 @@ class NodeImpl : public Node void initParameterInteraction() override { InitParameterInteraction(args()); } bilingual_str getWarnings() override { return Join(Assert(m_context->warnings)->GetMessages(), Untranslated("
")); } int getExitStatus() override { return Assert(m_context)->exit_status.load(); } - uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); } + BCLog::CategoryMask getLogCategories() override { return LogInstance().GetCategoryMask(); } bool baseInitialize() override { if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false; diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index 54e2c8e226f52..af2e1d0eaae14 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -244,15 +244,15 @@ static RPCHelpMan logging() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - uint32_t original_log_categories = LogInstance().GetCategoryMask(); + 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); } - uint32_t updated_log_categories = LogInstance().GetCategoryMask(); - uint32_t changed_log_categories = original_log_categories ^ updated_log_categories; + 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) {