Skip to content

Commit b31a0cd

Browse files
committed
log: expand BCLog::LogFlags (categories) to 64 bits
This will increase the maximum number of logging categories from 32 to 64.
1 parent ee57737 commit b31a0cd

File tree

4 files changed

+41
-39
lines changed

4 files changed

+41
-39
lines changed

src/interfaces/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <common/settings.h>
99
#include <consensus/amount.h> // For CAmount
10+
#include <logging.h> // For BCLog::CategoryMask
1011
#include <net.h> // For NodeId
1112
#include <net_types.h> // For banmap_t
1213
#include <netaddress.h> // For Network
@@ -84,7 +85,7 @@ class Node
8485
virtual int getExitStatus() = 0;
8586

8687
// Get log flags.
87-
virtual uint32_t getLogCategories() = 0;
88+
virtual BCLog::CategoryMask getLogCategories() = 0;
8889

8990
//! Initialize app dependencies.
9091
virtual bool baseInitialize() = 0;

src/logging.h

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,41 @@ struct LogCategory {
3737
};
3838

3939
namespace BCLog {
40-
enum LogFlags : uint32_t {
41-
NONE = 0,
42-
NET = (1 << 0),
43-
TOR = (1 << 1),
44-
MEMPOOL = (1 << 2),
45-
HTTP = (1 << 3),
46-
BENCH = (1 << 4),
47-
ZMQ = (1 << 5),
48-
WALLETDB = (1 << 6),
49-
RPC = (1 << 7),
50-
ESTIMATEFEE = (1 << 8),
51-
ADDRMAN = (1 << 9),
52-
SELECTCOINS = (1 << 10),
53-
REINDEX = (1 << 11),
54-
CMPCTBLOCK = (1 << 12),
55-
RAND = (1 << 13),
56-
PRUNE = (1 << 14),
57-
PROXY = (1 << 15),
58-
MEMPOOLREJ = (1 << 16),
59-
LIBEVENT = (1 << 17),
60-
COINDB = (1 << 18),
61-
QT = (1 << 19),
62-
LEVELDB = (1 << 20),
63-
VALIDATION = (1 << 21),
64-
I2P = (1 << 22),
65-
IPC = (1 << 23),
40+
using CategoryMask = uint64_t;
41+
enum LogFlags : CategoryMask {
42+
NONE = CategoryMask{0},
43+
NET = (CategoryMask{1} << 0),
44+
TOR = (CategoryMask{1} << 1),
45+
MEMPOOL = (CategoryMask{1} << 2),
46+
HTTP = (CategoryMask{1} << 3),
47+
BENCH = (CategoryMask{1} << 4),
48+
ZMQ = (CategoryMask{1} << 5),
49+
WALLETDB = (CategoryMask{1} << 6),
50+
RPC = (CategoryMask{1} << 7),
51+
ESTIMATEFEE = (CategoryMask{1} << 8),
52+
ADDRMAN = (CategoryMask{1} << 9),
53+
SELECTCOINS = (CategoryMask{1} << 10),
54+
REINDEX = (CategoryMask{1} << 11),
55+
CMPCTBLOCK = (CategoryMask{1} << 12),
56+
RAND = (CategoryMask{1} << 13),
57+
PRUNE = (CategoryMask{1} << 14),
58+
PROXY = (CategoryMask{1} << 15),
59+
MEMPOOLREJ = (CategoryMask{1} << 16),
60+
LIBEVENT = (CategoryMask{1} << 17),
61+
COINDB = (CategoryMask{1} << 18),
62+
QT = (CategoryMask{1} << 19),
63+
LEVELDB = (CategoryMask{1} << 20),
64+
VALIDATION = (CategoryMask{1} << 21),
65+
I2P = (CategoryMask{1} << 22),
66+
IPC = (CategoryMask{1} << 23),
6667
#ifdef DEBUG_LOCKCONTENTION
67-
LOCK = (1 << 24),
68+
LOCK = (CategoryMask{1} << 24),
6869
#endif
69-
BLOCKSTORAGE = (1 << 25),
70-
TXRECONCILIATION = (1 << 26),
71-
SCAN = (1 << 27),
72-
TXPACKAGES = (1 << 28),
73-
ALL = ~(uint32_t)0,
70+
BLOCKSTORAGE = (CategoryMask{1} << 25),
71+
TXRECONCILIATION = (CategoryMask{1} << 26),
72+
SCAN = (CategoryMask{1} << 27),
73+
TXPACKAGES = (CategoryMask{1} << 28),
74+
ALL = ~NONE,
7475
};
7576
enum class Level {
7677
Trace = 0, // High-volume or detailed logging for development/debugging
@@ -119,7 +120,7 @@ namespace BCLog {
119120
std::atomic<Level> m_log_level{DEFAULT_LOG_LEVEL};
120121

121122
/** Log categories bitfield. */
122-
std::atomic<uint32_t> m_categories{BCLog::NONE};
123+
std::atomic<CategoryMask> m_categories{BCLog::NONE};
123124

124125
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;
125126

@@ -204,7 +205,7 @@ namespace BCLog {
204205
void SetLogLevel(Level level) { m_log_level = level; }
205206
bool SetLogLevel(std::string_view level);
206207

207-
uint32_t GetCategoryMask() const { return m_categories.load(); }
208+
CategoryMask GetCategoryMask() const { return m_categories.load(); }
208209

209210
void EnableCategory(LogFlags flag);
210211
bool EnableCategory(std::string_view str);

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class NodeImpl : public Node
100100
void initParameterInteraction() override { InitParameterInteraction(args()); }
101101
bilingual_str getWarnings() override { return Join(Assert(m_context->warnings)->GetMessages(), Untranslated("<hr />")); }
102102
int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
103-
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
103+
BCLog::CategoryMask getLogCategories() override { return LogInstance().GetCategoryMask(); }
104104
bool baseInitialize() override
105105
{
106106
if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false;

src/rpc/node.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ static RPCHelpMan logging()
244244
},
245245
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
246246
{
247-
uint32_t original_log_categories = LogInstance().GetCategoryMask();
247+
BCLog::CategoryMask original_log_categories = LogInstance().GetCategoryMask();
248248
if (request.params[0].isArray()) {
249249
EnableOrDisableLogCategories(request.params[0], true);
250250
}
251251
if (request.params[1].isArray()) {
252252
EnableOrDisableLogCategories(request.params[1], false);
253253
}
254-
uint32_t updated_log_categories = LogInstance().GetCategoryMask();
255-
uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
254+
BCLog::CategoryMask updated_log_categories = LogInstance().GetCategoryMask();
255+
BCLog::CategoryMask changed_log_categories = original_log_categories ^ updated_log_categories;
256256

257257
// Update libevent logging if BCLog::LIBEVENT has changed.
258258
if (changed_log_categories & BCLog::LIBEVENT) {

0 commit comments

Comments
 (0)