mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-11 11:16:09 -05:00
log: expand BCLog::LogFlags (categories) to 64 bits
This will increase the maximum number of logging categories from 32 to 64.
This commit is contained in:
parent
ee57737bd6
commit
b31a0cd037
4 changed files with 41 additions and 39 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <common/settings.h>
|
#include <common/settings.h>
|
||||||
#include <consensus/amount.h> // For CAmount
|
#include <consensus/amount.h> // For CAmount
|
||||||
|
#include <logging.h> // For BCLog::CategoryMask
|
||||||
#include <net.h> // For NodeId
|
#include <net.h> // For NodeId
|
||||||
#include <net_types.h> // For banmap_t
|
#include <net_types.h> // For banmap_t
|
||||||
#include <netaddress.h> // For Network
|
#include <netaddress.h> // For Network
|
||||||
|
@ -84,7 +85,7 @@ public:
|
||||||
virtual int getExitStatus() = 0;
|
virtual int getExitStatus() = 0;
|
||||||
|
|
||||||
// Get log flags.
|
// Get log flags.
|
||||||
virtual uint32_t getLogCategories() = 0;
|
virtual BCLog::CategoryMask getLogCategories() = 0;
|
||||||
|
|
||||||
//! Initialize app dependencies.
|
//! Initialize app dependencies.
|
||||||
virtual bool baseInitialize() = 0;
|
virtual bool baseInitialize() = 0;
|
||||||
|
|
|
@ -37,40 +37,41 @@ struct LogCategory {
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace BCLog {
|
namespace BCLog {
|
||||||
enum LogFlags : uint32_t {
|
using CategoryMask = uint64_t;
|
||||||
NONE = 0,
|
enum LogFlags : CategoryMask {
|
||||||
NET = (1 << 0),
|
NONE = CategoryMask{0},
|
||||||
TOR = (1 << 1),
|
NET = (CategoryMask{1} << 0),
|
||||||
MEMPOOL = (1 << 2),
|
TOR = (CategoryMask{1} << 1),
|
||||||
HTTP = (1 << 3),
|
MEMPOOL = (CategoryMask{1} << 2),
|
||||||
BENCH = (1 << 4),
|
HTTP = (CategoryMask{1} << 3),
|
||||||
ZMQ = (1 << 5),
|
BENCH = (CategoryMask{1} << 4),
|
||||||
WALLETDB = (1 << 6),
|
ZMQ = (CategoryMask{1} << 5),
|
||||||
RPC = (1 << 7),
|
WALLETDB = (CategoryMask{1} << 6),
|
||||||
ESTIMATEFEE = (1 << 8),
|
RPC = (CategoryMask{1} << 7),
|
||||||
ADDRMAN = (1 << 9),
|
ESTIMATEFEE = (CategoryMask{1} << 8),
|
||||||
SELECTCOINS = (1 << 10),
|
ADDRMAN = (CategoryMask{1} << 9),
|
||||||
REINDEX = (1 << 11),
|
SELECTCOINS = (CategoryMask{1} << 10),
|
||||||
CMPCTBLOCK = (1 << 12),
|
REINDEX = (CategoryMask{1} << 11),
|
||||||
RAND = (1 << 13),
|
CMPCTBLOCK = (CategoryMask{1} << 12),
|
||||||
PRUNE = (1 << 14),
|
RAND = (CategoryMask{1} << 13),
|
||||||
PROXY = (1 << 15),
|
PRUNE = (CategoryMask{1} << 14),
|
||||||
MEMPOOLREJ = (1 << 16),
|
PROXY = (CategoryMask{1} << 15),
|
||||||
LIBEVENT = (1 << 17),
|
MEMPOOLREJ = (CategoryMask{1} << 16),
|
||||||
COINDB = (1 << 18),
|
LIBEVENT = (CategoryMask{1} << 17),
|
||||||
QT = (1 << 19),
|
COINDB = (CategoryMask{1} << 18),
|
||||||
LEVELDB = (1 << 20),
|
QT = (CategoryMask{1} << 19),
|
||||||
VALIDATION = (1 << 21),
|
LEVELDB = (CategoryMask{1} << 20),
|
||||||
I2P = (1 << 22),
|
VALIDATION = (CategoryMask{1} << 21),
|
||||||
IPC = (1 << 23),
|
I2P = (CategoryMask{1} << 22),
|
||||||
|
IPC = (CategoryMask{1} << 23),
|
||||||
#ifdef DEBUG_LOCKCONTENTION
|
#ifdef DEBUG_LOCKCONTENTION
|
||||||
LOCK = (1 << 24),
|
LOCK = (CategoryMask{1} << 24),
|
||||||
#endif
|
#endif
|
||||||
BLOCKSTORAGE = (1 << 25),
|
BLOCKSTORAGE = (CategoryMask{1} << 25),
|
||||||
TXRECONCILIATION = (1 << 26),
|
TXRECONCILIATION = (CategoryMask{1} << 26),
|
||||||
SCAN = (1 << 27),
|
SCAN = (CategoryMask{1} << 27),
|
||||||
TXPACKAGES = (1 << 28),
|
TXPACKAGES = (CategoryMask{1} << 28),
|
||||||
ALL = ~(uint32_t)0,
|
ALL = ~NONE,
|
||||||
};
|
};
|
||||||
enum class Level {
|
enum class Level {
|
||||||
Trace = 0, // High-volume or detailed logging for development/debugging
|
Trace = 0, // High-volume or detailed logging for development/debugging
|
||||||
|
@ -119,7 +120,7 @@ namespace BCLog {
|
||||||
std::atomic<Level> m_log_level{DEFAULT_LOG_LEVEL};
|
std::atomic<Level> m_log_level{DEFAULT_LOG_LEVEL};
|
||||||
|
|
||||||
/** Log categories bitfield. */
|
/** Log categories bitfield. */
|
||||||
std::atomic<uint32_t> m_categories{BCLog::NONE};
|
std::atomic<CategoryMask> 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;
|
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 +205,7 @@ namespace BCLog {
|
||||||
void SetLogLevel(Level level) { m_log_level = level; }
|
void SetLogLevel(Level level) { m_log_level = level; }
|
||||||
bool SetLogLevel(std::string_view 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);
|
void EnableCategory(LogFlags flag);
|
||||||
bool EnableCategory(std::string_view str);
|
bool EnableCategory(std::string_view str);
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
void initParameterInteraction() override { InitParameterInteraction(args()); }
|
void initParameterInteraction() override { InitParameterInteraction(args()); }
|
||||||
bilingual_str getWarnings() override { return Join(Assert(m_context->warnings)->GetMessages(), Untranslated("<hr />")); }
|
bilingual_str getWarnings() override { return Join(Assert(m_context->warnings)->GetMessages(), Untranslated("<hr />")); }
|
||||||
int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
|
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
|
bool baseInitialize() override
|
||||||
{
|
{
|
||||||
if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false;
|
if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false;
|
||||||
|
|
|
@ -244,15 +244,15 @@ static RPCHelpMan logging()
|
||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](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()) {
|
if (request.params[0].isArray()) {
|
||||||
EnableOrDisableLogCategories(request.params[0], true);
|
EnableOrDisableLogCategories(request.params[0], true);
|
||||||
}
|
}
|
||||||
if (request.params[1].isArray()) {
|
if (request.params[1].isArray()) {
|
||||||
EnableOrDisableLogCategories(request.params[1], false);
|
EnableOrDisableLogCategories(request.params[1], false);
|
||||||
}
|
}
|
||||||
uint32_t updated_log_categories = LogInstance().GetCategoryMask();
|
BCLog::CategoryMask updated_log_categories = LogInstance().GetCategoryMask();
|
||||||
uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
|
BCLog::CategoryMask changed_log_categories = original_log_categories ^ updated_log_categories;
|
||||||
|
|
||||||
// Update libevent logging if BCLog::LIBEVENT has changed.
|
// Update libevent logging if BCLog::LIBEVENT has changed.
|
||||||
if (changed_log_categories & BCLog::LIBEVENT) {
|
if (changed_log_categories & BCLog::LIBEVENT) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue