Changeset View
Changeset View
Standalone View
Standalone View
src/logging.cpp
Show All 9 Lines | |||||
bool fLogIPs = DEFAULT_LOGIPS; | bool fLogIPs = DEFAULT_LOGIPS; | ||||
/** | /** | ||||
* NOTE: the logger instance is leaked on exit. This is ugly, but will be | * NOTE: the logger instance 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 | * 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. | * since the order of destruction of static/global objects is undefined. | ||||
* Consider if the logger gets destroyed, and then some later destructor calls | * 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 | * LogPrint, maybe indirectly, and you get a core dump at shutdown trying to | ||||
* access the logger. When the shutdown sequence is fully audited and tested, | * access the logger. When the shutdown sequence is fully audited and tested, | ||||
* explicit destruction of these objects can be implemented by changing this | * explicit destruction of these objects can be implemented by changing this | ||||
* from a raw pointer to a std::unique_ptr. | * from a raw pointer to a std::unique_ptr. | ||||
* | * | ||||
* This method of initialization was originally introduced in | * This method of initialization was originally introduced in | ||||
* ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c. | * ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c. | ||||
*/ | */ | ||||
BCLog::Logger &GetLogger() { | BCLog::Logger &GetLogger() { | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | const CLogCategoryDesc LogCategories[] = { | ||||
{BCLog::RAND, "rand"}, | {BCLog::RAND, "rand"}, | ||||
{BCLog::PRUNE, "prune"}, | {BCLog::PRUNE, "prune"}, | ||||
{BCLog::PROXY, "proxy"}, | {BCLog::PROXY, "proxy"}, | ||||
{BCLog::MEMPOOLREJ, "mempoolrej"}, | {BCLog::MEMPOOLREJ, "mempoolrej"}, | ||||
{BCLog::LIBEVENT, "libevent"}, | {BCLog::LIBEVENT, "libevent"}, | ||||
{BCLog::COINDB, "coindb"}, | {BCLog::COINDB, "coindb"}, | ||||
{BCLog::QT, "qt"}, | {BCLog::QT, "qt"}, | ||||
{BCLog::LEVELDB, "leveldb"}, | {BCLog::LEVELDB, "leveldb"}, | ||||
{BCLog::SCRIPT, "script"}, | |||||
{BCLog::TEST, "test"}, | |||||
{BCLog::WALLET, "wallet"}, | |||||
{BCLog::INIT, "init"}, | |||||
{BCLog::NOUI, "noui"}, | |||||
{BCLog::SYNC, "sync"}, | |||||
{BCLog::UTIL, "util"}, | |||||
{BCLog::ALL, "1"}, | {BCLog::ALL, "1"}, | ||||
{BCLog::ALL, "all"}, | {BCLog::ALL, "all"}, | ||||
}; | }; | ||||
bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str) { | bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str) { | ||||
if (str == "") { | if (str == "") { | ||||
flag = BCLog::ALL; | flag = BCLog::ALL; | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | |||||
bool BCLog::Logger::DisableCategory(const std::string &str) { | bool BCLog::Logger::DisableCategory(const std::string &str) { | ||||
BCLog::LogFlags flag; | BCLog::LogFlags flag; | ||||
if (!GetLogCategory(flag, str)) return false; | if (!GetLogCategory(flag, str)) return false; | ||||
DisableCategory(flag); | DisableCategory(flag); | ||||
return true; | return true; | ||||
} | } | ||||
bool BCLog::Logger::WillLogCategory(LogFlags category) const { | bool BCLog::Logger::WillLogCategory(LogFlags category) { | ||||
Fabien: It will require more change than I expected to make this const again, because the LogPrintStr… | |||||
// ALL is not meant to be used as a logging category, but only as a mask | // ALL is not meant to be used as a logging category, but only as a mask | ||||
// representing all categories. | // representing all categories. | ||||
if (category == BCLog::NONE || category == BCLog::ALL) { | if (category == BCLog::NONE || category == BCLog::ALL) { | ||||
LogPrintf("Error trying to log using a category mask instead of an " | LogPrintStr("Error trying to log using a category mask instead of an " | ||||
"explicit category.\n"); | "explicit category.\n"); | ||||
return true; | return true; | ||||
} | } | ||||
return (m_categories.load(std::memory_order_relaxed) & category) != 0; | return (m_categories.load(std::memory_order_relaxed) & category) != 0; | ||||
} | } | ||||
bool BCLog::Logger::DefaultShrinkDebugFile() const { | bool BCLog::Logger::DefaultShrinkDebugFile() const { | ||||
return m_categories != BCLog::NONE; | return m_categories != BCLog::NONE; | ||||
} | } |
It will require more change than I expected to make this const again, because the LogPrintStr method needs to modify some members (buffer, file descriptor, ...).
The way it worked in the previous version was not very elegant : LogPrintf is a macro that call GetLogger().LogPrintStr().
One solution may be to move the if(...) LogPrintStr section to the caller function LogAcceptCategory but I find it makes the code more fragmented and more difficult to follow.
Any thought ?