Changeset View
Changeset View
Standalone View
Standalone View
src/logging.h
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | enum LogFlags : uint32_t { | ||||
RAND = (1 << 13), | RAND = (1 << 13), | ||||
PRUNE = (1 << 14), | PRUNE = (1 << 14), | ||||
PROXY = (1 << 15), | PROXY = (1 << 15), | ||||
MEMPOOLREJ = (1 << 16), | MEMPOOLREJ = (1 << 16), | ||||
LIBEVENT = (1 << 17), | LIBEVENT = (1 << 17), | ||||
COINDB = (1 << 18), | COINDB = (1 << 18), | ||||
QT = (1 << 19), | QT = (1 << 19), | ||||
LEVELDB = (1 << 20), | LEVELDB = (1 << 20), | ||||
SCRIPT = (1 << 21), | |||||
TEST = (1 << 22), | |||||
WALLET = (1 << 23), | |||||
INIT = (1 << 24), | |||||
NOUI = (1 << 25), | |||||
SYNC = (1 << 26), | |||||
UTIL = (1 << 27), | |||||
ALL = ~uint32_t(0), | ALL = ~uint32_t(0), | ||||
}; | }; | ||||
class Logger { | class Logger { | ||||
private: | private: | ||||
FILE *m_fileout = nullptr; | FILE *m_fileout = nullptr; | ||||
std::mutex m_file_mutex; | std::mutex m_file_mutex; | ||||
std::list<std::string> m_msgs_before_open; | std::list<std::string> m_msgs_before_open; | ||||
Show All 30 Lines | public: | ||||
void ShrinkDebugFile(); | void ShrinkDebugFile(); | ||||
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); | ||||
/** 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 &GetLogger(); | BCLog::Logger &GetLogger(); | ||||
Show All 11 Lines | |||||
#define LogPrint(category, ...) \ | #define LogPrint(category, ...) \ | ||||
do { \ | do { \ | ||||
if (LogAcceptCategory((category))) { \ | if (LogAcceptCategory((category))) { \ | ||||
GetLogger().LogPrintStr(tfm::format(__VA_ARGS__)); \ | GetLogger().LogPrintStr(tfm::format(__VA_ARGS__)); \ | ||||
} \ | } \ | ||||
} while (0) | } while (0) | ||||
#define LogPrintf(...) \ | |||||
do { \ | |||||
GetLogger().LogPrintStr(tfm::format(__VA_ARGS__)); \ | |||||
} while (0) | |||||
#endif // BITCOIN_LOGGING_H | #endif // BITCOIN_LOGGING_H |