Changeset View
Changeset View
Standalone View
Standalone View
src/logging.h
Show All 17 Lines | |||||
static const bool DEFAULT_LOGTIMEMICROS = false; | static const bool DEFAULT_LOGTIMEMICROS = false; | ||||
static const bool DEFAULT_LOGIPS = false; | static const bool DEFAULT_LOGIPS = false; | ||||
static const bool DEFAULT_LOGTIMESTAMPS = true; | static const bool DEFAULT_LOGTIMESTAMPS = true; | ||||
extern bool fLogIPs; | extern bool fLogIPs; | ||||
extern const char *const DEFAULT_DEBUGLOGFILE; | extern const char *const DEFAULT_DEBUGLOGFILE; | ||||
struct CLogCategoryActive { | |||||
std::string category; | |||||
bool active; | |||||
}; | |||||
nakihito: From PR10150
https://github.com/bitcoin/bitcoin/pull/10150/files?file-filters%5B%5D=.cpp&file… | |||||
namespace BCLog { | namespace BCLog { | ||||
enum LogFlags : uint32_t { | enum LogFlags : uint32_t { | ||||
NONE = 0, | NONE = 0, | ||||
NET = (1 << 0), | NET = (1 << 0), | ||||
TOR = (1 << 1), | TOR = (1 << 1), | ||||
MEMPOOL = (1 << 2), | MEMPOOL = (1 << 2), | ||||
HTTP = (1 << 3), | HTTP = (1 << 3), | ||||
Show All 25 Lines | private: | ||||
/** | /** | ||||
* m_started_new_line is a state variable that will suppress printing of the | * m_started_new_line is a state variable that will suppress printing of the | ||||
* timestamp when multiple calls are made that don't end in a newline. | * timestamp when multiple calls are made that don't end in a newline. | ||||
*/ | */ | ||||
std::atomic_bool m_started_new_line{true}; | std::atomic_bool m_started_new_line{true}; | ||||
/** | /** | ||||
* Log categories bitfield. Leveldb/libevent need special handling if their | * Log categories bitfield. | ||||
nakihitoAuthorUnsubmitted Done Inline Actionsnakihito: From PR10150
https://github.com/bitcoin/bitcoin/pull/10150/files?file-filters%5B%5D=.cpp&file… | |||||
* flags are changed at runtime. | |||||
*/ | */ | ||||
std::atomic<uint32_t> m_categories{0}; | std::atomic<uint32_t> m_categories{0}; | ||||
std::string LogTimestampStr(const std::string &str); | std::string LogTimestampStr(const std::string &str); | ||||
public: | public: | ||||
bool m_print_to_console = false; | bool m_print_to_console = false; | ||||
bool m_print_to_file = true; | bool m_print_to_file = true; | ||||
bool m_log_timestamps = DEFAULT_LOGTIMESTAMPS; | bool m_log_timestamps = DEFAULT_LOGTIMESTAMPS; | ||||
bool m_log_time_micros = DEFAULT_LOGTIMEMICROS; | bool m_log_time_micros = DEFAULT_LOGTIMEMICROS; | ||||
std::atomic<bool> m_reopen_file{false}; | std::atomic<bool> m_reopen_file{false}; | ||||
~Logger(); | ~Logger(); | ||||
/** Send a string to the log output */ | /** Send a string to the log output */ | ||||
void LogPrintStr(const std::string &str); | void LogPrintStr(const std::string &str); | ||||
fs::path GetDebugLogPath(); | fs::path GetDebugLogPath(); | ||||
bool OpenDebugLog(); | bool OpenDebugLog(); | ||||
void ShrinkDebugFile(); | void ShrinkDebugFile(); | ||||
uint32_t GetCategoryMask() const { return m_categories.load(); } | |||||
nakihitoAuthorUnsubmitted Done Inline ActionsFrom PR12954. nakihito: From PR12954. | |||||
nakihitoAuthorUnsubmitted Done Inline Actionsnakihito: https://github.com/bitcoin/bitcoin/pull/12954/files#diff-d278fc7d6997679f1f7416c5eda758fcR97 | |||||
void EnableCategory(LogFlags category); | void EnableCategory(LogFlags category); | ||||
bool EnableCategory(const std::string &str); | bool EnableCategory(const std::string &str); | ||||
void DisableCategory(LogFlags category); | void DisableCategory(LogFlags category); | ||||
bool DisableCategory(const std::string &str); | bool DisableCategory(const std::string &str); | ||||
/** Return true if log accepts specified category */ | /** Return true if log accepts specified category */ | ||||
bool WillLogCategory(LogFlags category) const; | bool WillLogCategory(LogFlags category) const; | ||||
/** Default for whether ShrinkDebugFile should be run */ | /** Default for whether ShrinkDebugFile should be run */ | ||||
bool DefaultShrinkDebugFile() const; | bool DefaultShrinkDebugFile() const; | ||||
}; | }; | ||||
} // namespace BCLog | } // namespace BCLog | ||||
BCLog::Logger &GetLogger(); | BCLog::Logger &GetLogger(); | ||||
/** Return true if log accepts specified category */ | /** Return true if log accepts specified category */ | ||||
static inline bool LogAcceptCategory(BCLog::LogFlags category) { | static inline bool LogAcceptCategory(BCLog::LogFlags category) { | ||||
return GetLogger().WillLogCategory(category); | return GetLogger().WillLogCategory(category); | ||||
} | } | ||||
/** Returns a string with the supported log categories */ | /** Returns a string with the log categories. */ | ||||
nakihitoAuthorUnsubmitted Done Inline Actionsnakihito: From PR10150
https://github.com/bitcoin/bitcoin/pull/10150/files?file-filters%5B%5D=.cpp&file… | |||||
std::string ListLogCategories(); | std::string ListLogCategories(); | ||||
/** Returns a vector of the active log categories. */ | |||||
std::vector<CLogCategoryActive> ListActiveLogCategories(); | |||||
nakihitoAuthorUnsubmitted Done Inline Actionsnakihito: From PR10150
https://github.com/bitcoin/bitcoin/pull/10150/files?file-filters%5B%5D=.cpp&file… | |||||
/** Return true if str parses as a log category and set the flag */ | /** Return true if str parses as a log category and set the flag */ | ||||
bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str); | bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str); | ||||
// Be conservative when using LogPrintf/error or other things which | // Be conservative when using LogPrintf/error or other things which | ||||
// unconditionally log to debug.log! It should not be the case that an inbound | // unconditionally log to debug.log! It should not be the case that an inbound | ||||
// peer can fill up a users disk with debug.log entries. | // peer can fill up a users disk with debug.log entries. | ||||
static inline void MarkUsed() {} | static inline void MarkUsed() {} | ||||
Show All 38 Lines |
From PR10150
https://github.com/bitcoin/bitcoin/pull/10150/files?file-filters%5B%5D=.cpp&file-filters%5B%5D=.h#diff-772f489c7d0a32de3badbfbcb5fd200dR72