5#ifndef BITCOIN_UTIL_LOG_H
6#define BITCOIN_UTIL_LOG_H
13#include <source_location>
25 std::source_location loc = std::source_location::current())
29 std::uint_least32_t
line()
const {
return m_loc.line(); }
70template <
typename... Args>
77 log_msg =
"Error \"" + std::string{fmterr.what()} +
"\" while formatting log message: " + fmt.fmt;
82 .should_ratelimit = should_ratelimit,
83 .source_loc = std::move(source_loc),
84 .message = std::move(log_msg)});
89#define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__)
95#define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, true, __VA_ARGS__)
96#define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, true, __VA_ARGS__)
97#define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, true, __VA_ARGS__)
105#define detail_LogIfCategoryAndLevelEnabled(category, level, ...) \
107 if (util::log::ShouldLog((category), (level))) { \
108 bool rate_limit{level >= BCLog::Level::Info}; \
109 Assume(!rate_limit); \
110 LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \
115#define LogDebug(category, ...) detail_LogIfCategoryAndLevelEnabled(category, BCLog::Level::Debug, __VA_ARGS__)
116#define LogTrace(category, ...) detail_LogIfCategoryAndLevelEnabled(category, BCLog::Level::Trace, __VA_ARGS__)
Like std::source_location, but allowing to override the function name.
SourceLocation(const char *func, std::source_location loc=std::source_location::current())
The func argument must be constructed from the C++11 func macro.
std::string_view function_name_short() const
std::source_location m_loc
std::string_view file_name() const
std::uint_least32_t line() const
void LogPrintFormatInternal(SourceLocation &&source_loc, BCLog::LogFlags flag, BCLog::Level level, bool should_ratelimit, util::ConstevalFormatString< sizeof...(Args)> fmt, const Args &... args)
void Log(Entry entry)
Send message to be logged.
uint64_t Category
Opaque to util::log; interpreted by consumers (e.g., BCLog::LogFlags).
bool ShouldLog(Category category, Level level)
Return whether messages with specified category and level should be logged.
SourceLocation source_loc
bool should_ratelimit
Hint for consumers if this entry should be ratelimited.