Bitcoin Core 28.99.0
P2P Digital Currency
Namespaces | Functions | Variables
logging.cpp File Reference
#include <logging.h>
#include <memusage.h>
#include <util/check.h>
#include <util/fs.h>
#include <util/string.h>
#include <util/threadnames.h>
#include <util/time.h>
#include <array>
#include <map>
#include <optional>
Include dependency graph for logging.cpp:

Go to the source code of this file.

Namespaces

namespace  BCLog
 

Functions

BCLog::LoggerLogInstance ()
 
static int FileWriteStr (std::string_view str, FILE *fp)
 
bool GetLogCategory (BCLog::LogFlags &flag, std::string_view str)
 Return true if str parses as a log category and set the flag. More...
 
static std::string LogCategoryToStr (BCLog::LogFlags category)
 
static std::optional< BCLog::LevelGetLogLevel (std::string_view level_str)
 
static constexpr std::array< BCLog::Level, 3 > LogLevelsList ()
 Log severity levels that can be selected by the user. More...
 
std::string BCLog::LogEscapeMessage (std::string_view str)
 Belts and suspenders: make sure outgoing log messages don't contain potentially suspicious characters, such as terminal control codes. More...
 
static size_t MemUsage (const BCLog::Logger::BufferedLog &buflog)
 

Variables

const char *const DEFAULT_DEBUGLOGFILE = "debug.log"
 
constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL {BCLog::Level::Info}
 
bool fLogIPs = DEFAULT_LOGIPS
 
static const std::map< std::string, BCLog::LogFlags, std::less<> > LOG_CATEGORIES_BY_STR
 
static const std::unordered_map< BCLog::LogFlags, std::string > LOG_CATEGORIES_BY_FLAG
 

Function Documentation

◆ FileWriteStr()

static int FileWriteStr ( std::string_view  str,
FILE *  fp 
)
static

Definition at line 47 of file logging.cpp.

Here is the caller graph for this function:

◆ GetLogCategory()

bool GetLogCategory ( BCLog::LogFlags flag,
std::string_view  str 
)

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

Definition at line 216 of file logging.cpp.

Here is the caller graph for this function:

◆ GetLogLevel()

static std::optional< BCLog::Level > GetLogLevel ( std::string_view  level_str)
static

Definition at line 257 of file logging.cpp.

Here is the caller graph for this function:

◆ LogCategoryToStr()

static std::string LogCategoryToStr ( BCLog::LogFlags  category)
static

Definition at line 247 of file logging.cpp.

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

Here is the caller graph for this function:

◆ LogLevelsList()

static constexpr std::array< BCLog::Level, 3 > LogLevelsList ( )
staticconstexpr

Log severity levels that can be selected by the user.

Definition at line 285 of file logging.cpp.

Here is the caller graph for this function:

◆ MemUsage()

static size_t MemUsage ( const BCLog::Logger::BufferedLog buflog)
static

Definition at line 365 of file logging.cpp.

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 = "debug.log"

Definition at line 21 of file logging.cpp.

◆ fLogIPs

bool fLogIPs = DEFAULT_LOGIPS

Definition at line 45 of file logging.cpp.

◆ LOG_CATEGORIES_BY_FLAG

const std::unordered_map<BCLog::LogFlags, std::string> LOG_CATEGORIES_BY_FLAG
static
Initial value:
{
[](const auto& in) {
std::unordered_map<BCLog::LogFlags, std::string> out;
for (const auto& [k, v] : in) {
const bool inserted{out.emplace(v, k).second};
assert(inserted);
}
return out;
}
static const std::map< std::string, BCLog::LogFlags, std::less<> > LOG_CATEGORIES_BY_STR
Definition: logging.cpp:170
assert(!tx.IsCoinBase())

Definition at line 204 of file logging.cpp.

◆ LOG_CATEGORIES_BY_STR

const std::map<std::string, BCLog::LogFlags, std::less<> > LOG_CATEGORIES_BY_STR
static

Definition at line 170 of file logging.cpp.

◆ MAX_USER_SETABLE_SEVERITY_LEVEL

constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL {BCLog::Level::Info}
constexpr

Definition at line 22 of file logging.cpp.