6 #ifndef BITCOIN_LOGGING_H
7 #define BITCOIN_LOGGING_H
20 #include <unordered_map>
65 #ifdef DEBUG_LOCKCONTENTION
113 std::list<std::function<void(
const std::string&)>> m_print_callbacks
GUARDED_BY(
m_cs) {};
141 std::list<std::function<void(
const std::string&)>>::iterator
PushBackCallback(std::function<
void(
const std::string&)> fun)
144 m_print_callbacks.push_back(std::move(fun));
145 return --m_print_callbacks.end();
149 void DeleteCallback(std::list<std::function<
void(
const std::string&)>>::iterator it)
152 m_print_callbacks.erase(it);
165 return m_category_log_levels;
170 m_category_log_levels = levels;
222 template <
typename... Args>
231 log_msg =
"Error \"" + std::string(fmterr.what()) +
"\" while formatting log message: " + fmt;
237 #define LogPrintLevel_(category, level, ...) LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)
240 #define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, __VA_ARGS__)
241 #define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, __VA_ARGS__)
242 #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, __VA_ARGS__)
245 #define LogPrintf(...) LogInfo(__VA_ARGS__)
246 #define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::Info, __VA_ARGS__)
252 #define LogPrintLevel(category, level, ...) \
254 if (LogAcceptCategory((category), (level))) { \
255 LogPrintLevel_(category, level, __VA_ARGS__); \
260 #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__)
261 #define LogTrace(category, ...) LogPrintLevel(category, BCLog::Level::Trace, __VA_ARGS__)
264 #define LogPrint(category, ...) LogDebug(category, __VA_ARGS__)
static std::string LogLevelToStr(BCLog::Level level)
Returns the string representation of a log level.
bool m_always_print_category_level
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)
FILE *m_fileout GUARDED_BY(m_cs)
std::string GetLogPrefix(LogFlags category, Level level) const
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
static const bool DEFAULT_LOGTIMEMICROS
const char *const DEFAULT_DEBUGLOGFILE
static constexpr bool DEFAULT_LOGLEVELALWAYS
BCLog::Logger & LogInstance()
constexpr auto DEFAULT_LOG_LEVEL
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.