Changeset View
Changeset View
Standalone View
Standalone View
src/logging.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017-2019 The Bitcoin developers | // Copyright (c) 2017-2019 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_LOGGING_H | #ifndef BITCOIN_LOGGING_H | ||||
#define BITCOIN_LOGGING_H | #define BITCOIN_LOGGING_H | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <threadsafety.h> | #include <threadsafety.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <util/string.h> | |||||
#include <atomic> | #include <atomic> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <list> | #include <list> | ||||
#include <mutex> | #include <mutex> | ||||
#include <string> | #include <string> | ||||
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; | ||||
static const bool DEFAULT_LOGTHREADNAMES = false; | static const bool DEFAULT_LOGTHREADNAMES = false; | ||||
extern bool fLogIPs; | extern bool fLogIPs; | ||||
extern const char *const DEFAULT_DEBUGLOGFILE; | extern const char *const DEFAULT_DEBUGLOGFILE; | ||||
struct CLogCategoryActive { | struct LogCategory { | ||||
std::string category; | std::string category; | ||||
bool active; | bool active; | ||||
}; | }; | ||||
namespace BCLog { | namespace BCLog { | ||||
enum LogFlags : uint32_t { | enum LogFlags : uint32_t { | ||||
NONE = 0, | NONE = 0, | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | public: | ||||
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; | ||||
/** Returns a vector of the log categories */ | |||||
std::vector<LogCategory> LogCategoriesList(); | |||||
/** Returns a string with the log categories */ | |||||
std::string LogCategoriesString() { | |||||
return Join(LogCategoriesList(), ", ", | |||||
[&](const LogCategory &i) { return i.category; }); | |||||
}; | |||||
/** 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 &LogInstance(); | BCLog::Logger &LogInstance(); | ||||
/** 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 LogInstance().WillLogCategory(category); | return LogInstance().WillLogCategory(category); | ||||
} | } | ||||
/** Returns a string with the log categories. */ | |||||
std::string ListLogCategories(); | |||||
/** Returns a vector of the active log categories. */ | |||||
std::vector<CLogCategoryActive> ListActiveLogCategories(); | |||||
/** 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 user's disk with debug.log entries. | // peer can fill up a user's disk with debug.log entries. | ||||
template <typename... Args> | template <typename... Args> | ||||
static inline void LogPrintf(const char *fmt, const Args &... args) { | static inline void LogPrintf(const char *fmt, const Args &... args) { | ||||
Show All 33 Lines |