PRCYCoin  2.0.0.7rc1
P2P Digital Currency
Classes | Namespaces | Macros | Enumerations | Functions | Variables
logging.h File Reference
#include "fs.h"
#include "tinyformat.h"
#include <atomic>
#include <cstdint>
#include <list>
#include <mutex>
#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  CLogCategoryActive
 
class  BCLog::Logger
 

Namespaces

 BCLog
 

Macros

#define LogPrintf(...)
 
#define LogPrint(category, ...)
 

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::DB = (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::STAKING = (1 << 21), BCLog::MASTERNODE = (1 << 22),
  BCLog::MNBUDGET = (1 << 23), BCLog::MNPING = (1 << 24), BCLog::POA = (1 << 25), BCLog::SUPPLY = (1 << 26),
  BCLog::DELETETX = (1 << 27), BCLog::ALL = ~(uint32_t)0
}
 

Functions

std::string ListLogCategories ()
 Returns a string with the supported log categories. More...
 
std::vector< CLogCategoryActiveListActiveLogCategories ()
 Returns a vector of the active log categories. 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>
std::string FormatStringFromLogArgs (const char *fmt, const Args &... args)
 Get format string from VA_ARGS for error reporting. More...
 

Variables

const char *const DEFAULT_DEBUGLOGFILE
 
bool fLogIPs
 
BCLog::Logger *const g_logger
 NOTE: the logger instances is leaked on exit. More...
 

Macro Definition Documentation

◆ LogPrint

#define LogPrint (   category,
  ... 
)
Value:
do { \
if (LogAcceptCategory((category))) { \
LogPrintf(__VA_ARGS__); \
} \
} while(0)

Definition at line 162 of file logging.h.

◆ LogPrintf

#define LogPrintf (   ...)
Value:
do { \
if(g_logger->Enabled()) { \
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
try { \
_log_msg_ = tfm::format(__VA_ARGS__); \
} catch (tinyformat::format_error &e) { \
/* Original format string will have newline so don't add one here */ \
_log_msg_ = "Error \"" + std::string(e.what()) + \
"\" while formatting log message: " + \
FormatStringFromLogArgs(__VA_ARGS__); \
} \
g_logger->LogPrintStr(_log_msg_); \
} \
} while(0)

Definition at line 147 of file logging.h.

Function Documentation

◆ FormatStringFromLogArgs()

template<typename... Args>
std::string FormatStringFromLogArgs ( const char *  fmt,
const Args &...  args 
)

Get format string from VA_ARGS for error reporting.

Definition at line 141 of file logging.h.

◆ 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 134 of file logging.cpp.

Here is the caller graph for this function:

◆ ListActiveLogCategories()

std::vector<CLogCategoryActive> ListActiveLogCategories ( )

Returns a vector of the active log categories.

Definition at line 164 of file logging.cpp.

Here is the caller graph for this function:

◆ ListLogCategories()

std::string ListLogCategories ( )

Returns a string with the supported log categories.

Definition at line 149 of file logging.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_DEBUGLOGFILE

const char* const DEFAULT_DEBUGLOGFILE

Definition at line 12 of file logging.cpp.

◆ fLogIPs

bool fLogIPs

Definition at line 30 of file logging.cpp.

◆ g_logger

BCLog::Logger* const g_logger

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.

This method of initialization was originally introduced in bitcoin@ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c.

Definition at line 28 of file logging.cpp.

g_logger
BCLog::Logger *const g_logger
NOTE: the logger instances is leaked on exit.
Definition: logging.cpp:28
tinyformat::format
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:958
BCLog::Logger::Enabled
bool Enabled() const
Returns whether logs will be written to any output.
Definition: logging.h:104
tinyformat::format_error
Definition: tinyformat.h:170