6 #ifndef BITCOIN_LOGGING_H
7 #define BITCOIN_LOGGING_H
20 #include <unordered_map>
64 #ifdef DEBUG_LOCKCONTENTION
112 std::list<std::function<void(
const std::string&)>> m_print_callbacks
GUARDED_BY(
m_cs) {};
137 std::list<std::function<void(
const std::string&)>>::iterator
PushBackCallback(std::function<
void(
const std::string&)> fun)
140 m_print_callbacks.push_back(std::move(fun));
141 return --m_print_callbacks.end();
145 void DeleteCallback(std::list<std::function<
void(
const std::string&)>>::iterator it)
148 m_print_callbacks.erase(it);
161 return m_category_log_levels;
166 m_category_log_levels = levels;
218 template <
typename... Args>
227 log_msg =
"Error \"" + std::string(fmterr.what()) +
"\" while formatting log message: " + fmt;
233 #define LogPrintLevel_(category, level, ...) LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)
236 #define LogPrintf(...) LogPrintLevel_(BCLog::LogFlags::NONE, BCLog::Level::None, __VA_ARGS__)
239 #define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__)
245 #define LogPrint(category, ...) \
247 if (LogAcceptCategory((category), BCLog::Level::Debug)) { \
248 LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__); \
253 #define LogPrintLevel(category, level, ...) \
255 if (LogAcceptCategory((category), (level))) { \
256 LogPrintLevel_(category, level, __VA_ARGS__); \
260 template <
typename... Args>
bool m_buffering GUARDED_BY(m_cs)
Buffer messages before logging can be started.
bool WillLogCategory(LogFlags category) const
std::list< std::function< void(const std::string &)> > m_print_callbacks GUARDED_BY(m_cs)
Slots that connect to the print signal.
bool Enabled() const
Returns whether logs will be written to any output.
std::string LogTimestampStr(const std::string &str)
void DisconnectTestLogger()
Only for testing.
std::list< std::string > m_msgs_before_open GUARDED_BY(m_cs)
std::list< std::function< void(const std::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun)
Connect a slot to the print signal and return the connection.
std::atomic< uint32_t > m_categories
Log categories bitfield.
bool DefaultShrinkDebugFile() const
std::unordered_map< LogFlags, Level > m_category_log_levels GUARDED_BY(m_cs)
Category-specific log level. Overrides m_log_level.
bool m_log_sourcelocations
void SetLogLevel(Level level)
std::atomic< Level > m_log_level
If there is no category-specific log level, all logs with a severity level lower than m_log_level wil...
bool WillLogCategoryLevel(LogFlags category, Level level) const
std::unordered_map< LogFlags, Level > CategoryLevels() const
std::atomic_bool m_started_new_line
m_started_new_line is a state variable that will suppress printing of the timestamp when multiple cal...
void LogPrintStr(const std::string &str, const std::string &logging_function, const std::string &source_file, int source_line, BCLog::LogFlags category, BCLog::Level level)
Send a string to the log output.
std::vector< LogCategory > LogCategoriesList() const
Returns a vector of the log categories in alphabetical order.
void EnableCategory(LogFlags flag)
bool StartLogging()
Start logging (and flush all buffered messages)
std::string LogLevelToStr(BCLog::Level level) const
Returns the string representation of a log level.
FILE *m_fileout GUARDED_BY(m_cs)
std::string LogLevelsString() const
Returns a string with all user-selectable log levels.
void DeleteCallback(std::list< std::function< void(const std::string &)>>::iterator it)
Delete a connection.
std::atomic< bool > m_reopen_file
uint32_t GetCategoryMask() const
void SetCategoryLogLevel(const std::unordered_map< LogFlags, Level > &levels)
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
void DisableCategory(LogFlags flag)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static const bool DEFAULT_LOGTIMESTAMPS
static void LogPrintf_(const std::string &logging_function, const std::string &source_file, const int source_line, const BCLog::LogFlags flag, const BCLog::Level level, const char *fmt, const Args &... args)
static const bool DEFAULT_LOGIPS
static const bool DEFAULT_LOGTHREADNAMES
static bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
Return true if log accepts specified category, at the specified level.
bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str)
Return true if str parses as a log category and set the flag.
static const bool DEFAULT_LOGSOURCELOCATIONS
bool error(const char *fmt, const Args &... args)
static const bool DEFAULT_LOGTIMEMICROS
const char *const DEFAULT_DEBUGLOGFILE
BCLog::Logger & LogInstance()
constexpr auto DEFAULT_LOG_LEVEL
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.