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-2018 The Bitcoin developers | // Copyright (c) 2017-2018 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 <atomic> | #include <atomic> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <list> | |||||
#include <string> | #include <string> | ||||
#include <boost/thread/mutex.hpp> | |||||
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; | ||||
extern bool fLogIPs; | extern bool fLogIPs; | ||||
extern std::atomic<bool> fReopenDebugLog; | |||||
extern std::atomic<uint32_t> logCategories; | extern std::atomic<uint32_t> logCategories; | ||||
namespace BCLog { | namespace BCLog { | ||||
enum LogFlags : uint32_t { | enum LogFlags : uint32_t { | ||||
NONE = 0, | NONE = 0, | ||||
NET = (1 << 0), | NET = (1 << 0), | ||||
Show All 17 Lines | enum LogFlags : uint32_t { | ||||
COINDB = (1 << 18), | COINDB = (1 << 18), | ||||
QT = (1 << 19), | QT = (1 << 19), | ||||
LEVELDB = (1 << 20), | LEVELDB = (1 << 20), | ||||
ALL = ~uint32_t(0), | ALL = ~uint32_t(0), | ||||
}; | }; | ||||
class Logger { | class Logger { | ||||
private: | private: | ||||
FILE *fileout = nullptr; | |||||
boost::mutex mutexDebugLog; | |||||
std::list<std::string> vMsgsBeforeOpenLog; | |||||
/** | /** | ||||
* fStartedNewLine is a state variable that will suppress printing of the | * fStartedNewLine is a state variable that will suppress printing of the | ||||
* timestamp when multiple calls are made that don't end in a newline. | * timestamp when multiple calls are made that don't end in a newline. | ||||
*/ | */ | ||||
std::atomic_bool fStartedNewLine{true}; | std::atomic_bool fStartedNewLine{true}; | ||||
std::string LogTimestampStr(const std::string &str); | std::string LogTimestampStr(const std::string &str); | ||||
public: | public: | ||||
bool fPrintToConsole = false; | bool fPrintToConsole = false; | ||||
bool fPrintToDebugLog = true; | bool fPrintToDebugLog = true; | ||||
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS; | bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS; | ||||
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS; | bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS; | ||||
std::atomic<bool> fReopenDebugLog{false}; | std::atomic<bool> fReopenDebugLog{false}; | ||||
~Logger(); | |||||
/** Send a string to the log output */ | /** Send a string to the log output */ | ||||
int LogPrintStr(const std::string &str); | int LogPrintStr(const std::string &str); | ||||
void OpenDebugLog(); | |||||
void ShrinkDebugFile(); | |||||
}; | }; | ||||
} // namespace BCLog | } // namespace BCLog | ||||
BCLog::Logger &GetLogger(); | BCLog::Logger &GetLogger(); | ||||
/** Return true if log accepts specified category */ | /** Return true if log accepts specified category */ | ||||
static inline bool LogAcceptCategory(uint32_t category) { | static inline bool LogAcceptCategory(uint32_t category) { | ||||
Show All 13 Lines | do { \ | ||||
} \ | } \ | ||||
} while (0) | } while (0) | ||||
#define LogPrintf(...) \ | #define LogPrintf(...) \ | ||||
do { \ | do { \ | ||||
GetLogger().LogPrintStr(tfm::format(__VA_ARGS__)); \ | GetLogger().LogPrintStr(tfm::format(__VA_ARGS__)); \ | ||||
} while (0) | } while (0) | ||||
void OpenDebugLog(); | |||||
void ShrinkDebugFile(); | |||||
#endif // BITCOIN_LOGGING_H | #endif // BITCOIN_LOGGING_H |