7#ifndef BITCOIN_LOGGING_H
8#define BITCOIN_LOGGING_H
65#ifdef DEBUG_LOCKCONTENTION
107 std::list<std::function<void(
const std::string &)>>
126 const std::string &logging_function,
127 const std::string &source_file,
const int source_line,
134 !m_print_callbacks.empty();
138 std::list<std::function<void(
const std::string &)>>::iterator
141 m_print_callbacks.push_back(std::move(fun));
142 return --m_print_callbacks.end();
147 std::list<std::function<
void(
const std::string &)>>::iterator it) {
149 m_print_callbacks.erase(it);
202template <
typename... Args>
204LogPrintf_(
const std::string &logging_function,
const std::string &source_file,
206 const BCLog::Level level,
const char *fmt,
const Args &...args) {
215 log_msg =
"Error \"" + std::string(fmterr.what()) +
216 "\" while formatting log message: " + fmt;
219 source_line, flag, level);
223#define LogPrintLevel_(category, level, ...) \
224 LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)
227#define LogPrintf(...) \
228 LogPrintLevel_(BCLog::LogFlags::NONE, BCLog::Level::None, __VA_ARGS__)
231#define LogPrintfCategory(category, ...) \
232 LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__)
238#define LogPrint(category, ...) \
240 if (LogAcceptCategory((category), BCLog::Level::Debug)) { \
241 LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__); \
247#define LogPrintLevel(category, level, ...) \
249 if (LogAcceptCategory((category), (level))) { \
250 LogPrintLevel_(category, level, __VA_ARGS__); \
259#define LogPrintfToBeContinued LogPrintf
260#define LogPrintToBeContinued LogPrint
261#define LogPrintLevelToBeContinued LogPrintLevel
263template <
typename... Args>
bool error(
const char *fmt,
const Args &...args) {
FILE *m_fileout GUARDED_BY(m_cs)
bool m_buffering GUARDED_BY(m_cs)
Buffer messages before logging can be started.
bool WillLogCategory(LogFlags category) const
Return true if log accepts specified category.
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::function< void(conststd::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun)
Connect a slot to the print signal and return the connection.
std::list< std::string > m_msgs_before_open GUARDED_BY(m_cs)
std::atomic< uint32_t > m_categories
Log categories bitfield.
bool DefaultShrinkDebugFile() const
Default for whether ShrinkDebugFile should be run.
bool m_log_sourcelocations
void LogPrintStr(const std::string &str, const std::string &logging_function, const std::string &source_file, const int source_line, const BCLog::LogFlags category, const BCLog::Level level)
Send a string to the log output.
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...
std::vector< LogCategory > LogCategoriesList() const
Returns a vector of the log categories in alphabetical order.
void DisableCategory(LogFlags category)
void EnableCategory(LogFlags category)
bool StartLogging()
Start logging (and flush all buffered messages)
std::atomic< bool > m_reopen_file
uint32_t GetCategoryMask() const
std::list< std::function< void(const std::string &)> > m_print_callbacks GUARDED_BY(m_cs)
Slots that connect to the print signal.
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
void DeleteCallback(std::list< std::function< void(const std::string &)> >::iterator it)
Delete a connection.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool error(const char *fmt, const Args &...args)
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.
BCLog::Logger & LogInstance()
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
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.