6 #ifndef BITCOIN_LOGGING_H 7 #define BITCOIN_LOGGING_H 21 #include <unordered_map> 66 #ifdef DEBUG_LOCKCONTENTION 89 SystemClock::time_point
now;
115 std::unordered_map<LogFlags, Level> m_category_log_levels
GUARDED_BY(
m_cs);
124 void FormatLogStrInPlace(std::string& str,
LogFlags category,
Level level, std::string_view source_file,
int source_line, std::string_view logging_function, std::string_view threadname, SystemClock::time_point now, std::chrono::seconds mocktime)
const;
126 std::string
LogTimestampStr(SystemClock::time_point now, std::chrono::seconds mocktime)
const;
129 std::list<std::function<void(const std::string&)>> m_print_callbacks
GUARDED_BY(
m_cs) {};
165 m_print_callbacks.push_back(std::move(fun));
166 return --m_print_callbacks.end();
173 m_print_callbacks.erase(it);
194 return m_category_log_levels;
199 m_category_log_levels = levels;
251 template <
typename... Args>
260 log_msg =
"Error \"" + std::string(fmterr.what()) +
"\" while formatting log message: " + fmt;
266 #define LogPrintLevel_(category, level, ...) LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__) 269 #define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, __VA_ARGS__) 270 #define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, __VA_ARGS__) 271 #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, __VA_ARGS__) 274 #define LogPrintf(...) LogInfo(__VA_ARGS__) 275 #define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::Info, __VA_ARGS__) 281 #define LogPrintLevel(category, level, ...) \ 283 if (LogAcceptCategory((category), (level))) { \ 284 LogPrintLevel_(category, level, __VA_ARGS__); \ 289 #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) 290 #define LogTrace(category, ...) LogPrintLevel(category, BCLog::Level::Trace, __VA_ARGS__) 293 #define LogPrint(category, ...) LogDebug(category, __VA_ARGS__) 295 #endif // BITCOIN_LOGGING_H void EnableCategory(LogFlags flag)
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Disable logging This offers a slight speedup and slightly smaller memory usage compared to leaving th...
size_t m_buffer_lines_discarded GUARDED_BY(m_cs)
FILE *m_fileout GUARDED_BY(m_cs)
std::unordered_map< LogFlags, Level > CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
static void LogPrintf_(std::string_view logging_function, std::string_view source_file, const int source_line, const BCLog::LogFlags flag, const BCLog::Level level, const char *fmt, const Args &... args)
static const bool DEFAULT_LOGTHREADNAMES
std::chrono::seconds mocktime
static const bool DEFAULT_LOGTIMEMICROS
std::atomic< bool > m_reopen_file
SystemClock::time_point now
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...
BCLog::Logger & LogInstance()
bool m_log_sourcelocations
constexpr auto DEFAULT_LOG_LEVEL
bool Enabled() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Returns whether logs will be written to any output.
static constexpr bool DEFAULT_LOGLEVELALWAYS
bool m_always_print_category_level
std::string LogTimestampStr(SystemClock::time_point now, std::chrono::seconds mocktime) const
void FormatLogStrInPlace(std::string &str, LogFlags category, Level level, std::string_view source_file, int source_line, std::string_view logging_function, std::string_view threadname, SystemClock::time_point now, std::chrono::seconds mocktime) const
constexpr size_t DEFAULT_MAX_LOG_BUFFER
uint32_t GetCategoryMask() const
void DisableCategory(LogFlags flag)
void SetCategoryLogLevel(const std::unordered_map< LogFlags, Level > &levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
void SetLogLevel(Level level)
bool WillLogCategory(LogFlags category) const
void DeleteCallback(std::list< std::function< void(const std::string &)>>::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Delete a connection.
std::atomic< uint32_t > m_categories
Log categories bitfield.
std::string GetLogPrefix(LogFlags category, Level level) const
void DisconnectTestLogger() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Only for testing.
void LogPrintStr_(std::string_view str, std::string_view logging_function, std::string_view source_file, int source_line, BCLog::LogFlags category, BCLog::Level level) EXCLUSIVE_LOCKS_REQUIRED(m_cs)
Send a string to the log output (internal)
static std::string LogLevelToStr(BCLog::Level level)
Returns the string representation of a log level.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void LogPrintStr(std::string_view str, std::string_view logging_function, std::string_view source_file, int source_line, BCLog::LogFlags category, BCLog::Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Send a string to the log output.
std::list< std::function< void(const std::string &)> > m_print_callbacks GUARDED_BY(m_cs)
Slots that connect to the print signal.
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::list< std::function< void(const std::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Connect a slot to the print signal and return the connection.
std::string logging_function
static const bool DEFAULT_LOGSOURCELOCATIONS
bool StartLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Start logging (and flush all buffered messages)
std::string LogLevelsString() const
Returns a string with all user-selectable log levels.
std::vector< LogCategory > LogCategoriesList() const
Returns a vector of the log categories in alphabetical order.
size_t m_cur_buffer_memusage GUARDED_BY(m_cs)
static bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
Return true if log accepts specified category, at the specified level.
static const bool DEFAULT_LOGIPS
size_t m_max_buffer_memusage GUARDED_BY(m_cs)
bool WillLogCategoryLevel(LogFlags category, Level level) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
const char *const DEFAULT_DEBUGLOGFILE
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
static const bool DEFAULT_LOGTIMESTAMPS
bool GetLogCategory(BCLog::LogFlags &flag, std::string_view str)
Return true if str parses as a log category and set the flag.
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
bool DefaultShrinkDebugFile() const