Bitcoin Core  27.99.0
P2P Digital Currency
Classes | Namespaces | Macros | Enumerations | Functions | Variables
logging.h File Reference
#include <threadsafety.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/string.h>
#include <atomic>
#include <cstdint>
#include <functional>
#include <list>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
Include dependency graph for logging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LogCategory
 
class  BCLog::Logger
 

Namespaces

 BCLog
 

Macros

#define LogPrintLevel_(category, level, ...)   LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)
 
#define LogInfo(...)   LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, __VA_ARGS__)
 
#define LogWarning(...)   LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, __VA_ARGS__)
 
#define LogError(...)   LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, __VA_ARGS__)
 
#define LogPrintf(...)   LogInfo(__VA_ARGS__)
 
#define LogPrintfCategory(category, ...)   LogPrintLevel_(category, BCLog::Level::Info, __VA_ARGS__)
 
#define LogPrintLevel(category, level, ...)
 
#define LogDebug(category, ...)   LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__)
 
#define LogTrace(category, ...)   LogPrintLevel(category, BCLog::Level::Trace, __VA_ARGS__)
 
#define LogPrint(category, ...)   LogDebug(category, __VA_ARGS__)
 

Enumerations

enum  BCLog::LogFlags : uint32_t {
  BCLog::NONE = 0 , BCLog::NET = (1 << 0) , BCLog::TOR = (1 << 1) , BCLog::MEMPOOL = (1 << 2) ,
  BCLog::HTTP = (1 << 3) , BCLog::BENCH = (1 << 4) , BCLog::ZMQ = (1 << 5) , BCLog::WALLETDB = (1 << 6) ,
  BCLog::RPC = (1 << 7) , BCLog::ESTIMATEFEE = (1 << 8) , BCLog::ADDRMAN = (1 << 9) , BCLog::SELECTCOINS = (1 << 10) ,
  BCLog::REINDEX = (1 << 11) , BCLog::CMPCTBLOCK = (1 << 12) , BCLog::RAND = (1 << 13) , BCLog::PRUNE = (1 << 14) ,
  BCLog::PROXY = (1 << 15) , BCLog::MEMPOOLREJ = (1 << 16) , BCLog::LIBEVENT = (1 << 17) , BCLog::COINDB = (1 << 18) ,
  BCLog::QT = (1 << 19) , BCLog::LEVELDB = (1 << 20) , BCLog::VALIDATION = (1 << 21) , BCLog::I2P = (1 << 22) ,
  BCLog::IPC = (1 << 23) , BCLog::BLOCKSTORAGE = (1 << 25) , BCLog::TXRECONCILIATION = (1 << 26) , BCLog::SCAN = (1 << 27) ,
  BCLog::TXPACKAGES = (1 << 28) , BCLog::ALL = ~(uint32_t)0
}
 
enum class  BCLog::Level {
  BCLog::Trace = 0 , BCLog::Debug , BCLog::Info , BCLog::Warning ,
  BCLog::Error
}
 

Functions

BCLog::LoggerLogInstance ()
 
static bool LogAcceptCategory (BCLog::LogFlags category, BCLog::Level level)
 Return true if log accepts specified category, at the specified level. More...
 
bool GetLogCategory (BCLog::LogFlags &flag, const std::string &str)
 Return true if str parses as a log category and set the flag. More...
 
template<typename... Args>
static void LogPrintf_ (const std::string &logging_function, const std::string &source_file, const int source_line, const BCLog::LogFlags flag, const BCLog::Level level, const char *fmt, const Args &... args)
 

Variables

static const bool DEFAULT_LOGTIMEMICROS = false
 
static const bool DEFAULT_LOGIPS = false
 
static const bool DEFAULT_LOGTIMESTAMPS = true
 
static const bool DEFAULT_LOGTHREADNAMES = false
 
static const bool DEFAULT_LOGSOURCELOCATIONS = false
 
static constexpr bool DEFAULT_LOGLEVELALWAYS = false
 
const char *const DEFAULT_DEBUGLOGFILE
 
bool fLogIPs
 
constexpr auto BCLog::DEFAULT_LOG_LEVEL {Level::Debug}
 

Macro Definition Documentation

◆ LogDebug

#define LogDebug (   category,
  ... 
)    LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__)

Definition at line 259 of file logging.h.

◆ LogError

#define LogError (   ...)    LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, __VA_ARGS__)

Definition at line 241 of file logging.h.

◆ LogInfo

#define LogInfo (   ...)    LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, __VA_ARGS__)

Definition at line 239 of file logging.h.

◆ LogPrint

#define LogPrint (   category,
  ... 
)    LogDebug(category, __VA_ARGS__)

Definition at line 263 of file logging.h.

◆ LogPrintf

#define LogPrintf (   ...)    LogInfo(__VA_ARGS__)

Definition at line 244 of file logging.h.

◆ LogPrintfCategory

#define LogPrintfCategory (   category,
  ... 
)    LogPrintLevel_(category, BCLog::Level::Info, __VA_ARGS__)

Definition at line 245 of file logging.h.

◆ LogPrintLevel

#define LogPrintLevel (   category,
  level,
  ... 
)
Value:
do { \
if (LogAcceptCategory((category), (level))) { \
LogPrintLevel_(category, level, __VA_ARGS__); \
} \
} while (0)
static bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
Return true if log accepts specified category, at the specified level.
Definition: logging.h:209

Definition at line 251 of file logging.h.

◆ LogPrintLevel_

#define LogPrintLevel_ (   category,
  level,
  ... 
)    LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)

Definition at line 236 of file logging.h.

◆ LogTrace

#define LogTrace (   category,
  ... 
)    LogPrintLevel(category, BCLog::Level::Trace, __VA_ARGS__)

Definition at line 260 of file logging.h.

◆ LogWarning

#define LogWarning (   ...)    LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, __VA_ARGS__)

Definition at line 240 of file logging.h.

Function Documentation

◆ GetLogCategory()

bool GetLogCategory ( BCLog::LogFlags flag,
const std::string &  str 
)

Return true if str parses as a log category and set the flag.

Definition at line 201 of file logging.cpp.

Here is the caller graph for this function:

◆ LogAcceptCategory()

static bool LogAcceptCategory ( BCLog::LogFlags  category,
BCLog::Level  level 
)
inlinestatic

Return true if log accepts specified category, at the specified level.

Definition at line 209 of file logging.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogInstance()

BCLog::Logger& LogInstance ( )

NOTE: the logger instances is leaked on exit. This is ugly, but will be cleaned up by the OS/libc. Defining a logger as a global object doesn't work since the order of destruction of static/global objects is undefined. Consider if the logger gets destroyed, and then some later destructor calls LogPrintf, maybe indirectly, and you get a core dump at shutdown trying to access the logger. When the shutdown sequence is fully audited and tested, explicit destruction of these objects can be implemented by changing this from a raw pointer to a std::unique_ptr. Since the ~Logger() destructor is never called, the Logger class and all its subclasses must have implicitly-defined destructors.

This method of initialization was originally introduced in ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c.

Definition at line 23 of file logging.cpp.

Here is the caller graph for this function:

◆ LogPrintf_()

template<typename... Args>
static void LogPrintf_ ( const std::string &  logging_function,
const std::string &  source_file,
const int  source_line,
const BCLog::LogFlags  flag,
const BCLog::Level  level,
const char *  fmt,
const Args &...  args 
)
inlinestatic

Definition at line 222 of file logging.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_DEBUGLOGFILE

const char* const DEFAULT_DEBUGLOGFILE
extern

Definition at line 20 of file logging.cpp.

◆ DEFAULT_LOGIPS

const bool DEFAULT_LOGIPS = false
static

Definition at line 24 of file logging.h.

◆ DEFAULT_LOGLEVELALWAYS

constexpr bool DEFAULT_LOGLEVELALWAYS = false
staticconstexpr

Definition at line 28 of file logging.h.

◆ DEFAULT_LOGSOURCELOCATIONS

const bool DEFAULT_LOGSOURCELOCATIONS = false
static

Definition at line 27 of file logging.h.

◆ DEFAULT_LOGTHREADNAMES

const bool DEFAULT_LOGTHREADNAMES = false
static

Definition at line 26 of file logging.h.

◆ DEFAULT_LOGTIMEMICROS

const bool DEFAULT_LOGTIMEMICROS = false
static

Definition at line 23 of file logging.h.

◆ DEFAULT_LOGTIMESTAMPS

const bool DEFAULT_LOGTIMESTAMPS = true
static

Definition at line 25 of file logging.h.

◆ fLogIPs

bool fLogIPs
extern

Definition at line 44 of file logging.cpp.