Skip to content

Commit

Permalink
log: expand BCLog::LogFlags (categories) to 64 bits
Browse files Browse the repository at this point in the history
This will increase the maximum number of logging categories
from 32 to 64.
  • Loading branch information
LarryRuane committed Aug 12, 2024
1 parent ee57737 commit 9bed303
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Node
virtual int getExitStatus() = 0;

// Get log flags.
virtual uint32_t getLogCategories() = 0;
virtual uint64_t getLogCategories() = 0;

//! Initialize app dependencies.
virtual bool baseInitialize() = 0;
Expand Down
66 changes: 33 additions & 33 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,40 @@ struct LogCategory {
};

namespace BCLog {
enum LogFlags : uint32_t {
enum LogFlags : uint64_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),
NET = (1ULL << 0),
TOR = (1ULL << 1),
MEMPOOL = (1ULL << 2),
HTTP = (1ULL << 3),
BENCH = (1ULL << 4),
ZMQ = (1ULL << 5),
WALLETDB = (1ULL << 6),
RPC = (1ULL << 7),
ESTIMATEFEE = (1ULL << 8),
ADDRMAN = (1ULL << 9),
SELECTCOINS = (1ULL << 10),
REINDEX = (1ULL << 11),
CMPCTBLOCK = (1ULL << 12),
RAND = (1ULL << 13),
PRUNE = (1ULL << 14),
PROXY = (1ULL << 15),
MEMPOOLREJ = (1ULL << 16),
LIBEVENT = (1ULL << 17),
COINDB = (1ULL << 18),
QT = (1ULL << 19),
LEVELDB = (1ULL << 20),
VALIDATION = (1ULL << 21),
I2P = (1ULL << 22),
IPC = (1ULL << 23),
#ifdef DEBUG_LOCKCONTENTION
LOCK = (1 << 24),
LOCK = (1ULL << 24),
#endif
BLOCKSTORAGE = (1 << 25),
TXRECONCILIATION = (1 << 26),
SCAN = (1 << 27),
TXPACKAGES = (1 << 28),
ALL = ~(uint32_t)0,
BLOCKSTORAGE = (1ULL << 25),
TXRECONCILIATION = (1ULL << 26),
SCAN = (1ULL << 27),
TXPACKAGES = (1ULL << 28),
ALL = ~0ULL,
};
enum class Level {
Trace = 0, // High-volume or detailed logging for development/debugging
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace BCLog {
std::atomic<Level> m_log_level{DEFAULT_LOG_LEVEL};

/** Log categories bitfield. */
std::atomic<uint32_t> m_categories{BCLog::NONE};
std::atomic<uint64_t> 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;

Expand Down Expand Up @@ -204,7 +204,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(); }
uint64_t GetCategoryMask() const { return m_categories.load(); }

void EnableCategory(LogFlags flag);
bool EnableCategory(std::string_view str);
Expand Down
2 changes: 1 addition & 1 deletion src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("<hr />")); }
int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
uint64_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
bool baseInitialize() override
{
if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false;
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ static RPCHelpMan logging()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
uint32_t original_log_categories = LogInstance().GetCategoryMask();
uint64_t 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;
uint64_t updated_log_categories = LogInstance().GetCategoryMask();
uint64_t changed_log_categories = original_log_categories ^ updated_log_categories;

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

0 comments on commit 9bed303

Please sign in to comment.