5#ifndef BITCOIN_UTIL_LOG_H
6#define BITCOIN_UTIL_LOG_H
18#include <source_location>
31 std::source_location loc = std::source_location::current())
35 std::uint_least32_t
line()
const {
return m_loc.line(); }
65 SystemClock::time_point
timestamp{SystemClock::now()};
83template <
typename... Args>
90 log_msg =
"Error \"" + std::string{fmterr.what()} +
"\" while formatting log message: " + fmt.fmt;
95 .should_ratelimit = should_ratelimit,
96 .source_loc = std::move(source_loc),
97 .message = std::move(log_msg)});
100template <
typename... Args>
106template <
typename... Args>
120#define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__)
126#define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__)
127#define LogWarning(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Warning, __VA_ARGS__)
128#define LogError(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Error, __VA_ARGS__)
136#define detail_LogIfCategoryAndLevelEnabled(category, shouldlog, level, ...) \
138 if (shouldlog(category)) { \
139 detail_LogWithSrcLoc((category), (level), util::log::NO_RATE_LIMIT, __VA_ARGS__); \
144#define LogDebug(category, ...) detail_LogIfCategoryAndLevelEnabled(category, util::log::ShouldDebugLog, util::log::Level::Debug, __VA_ARGS__)
145#define LogTrace(category, ...) detail_LogIfCategoryAndLevelEnabled(category, util::log::ShouldTraceLog, util::log::Level::Trace, __VA_ARGS__)
148#define LogWarnThenDebug(category, ...) \
150 static std::atomic<bool> _warned{false}; \
151 if (!_warned.exchange(true)) { \
152 LogWarning(__VA_ARGS__); \
154 LogDebug(category, __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 Log(Entry entry)
Send message to be logged.
bool ShouldDebugLog(Category)
Return whether messages with specified category should be debug logged.
bool ShouldTraceLog(Category)
Return whether messages with specified category should be trace logged.
uint64_t Category
Opaque to util::log; interpreted by consumers (e.g., BCLog::LogFlags).
constexpr NoRateLimitTag NO_RATE_LIMIT
void LogPrintFormatInternal_(SourceLocation &&source_loc, BCLog::LogFlags flag, util::log::Level level, bool should_ratelimit, util::ConstevalFormatString< sizeof...(Args)> fmt, const Args &... args)
void LogPrintFormatInternal(SourceLocation &&source_loc, BCLog::LogFlags flag, util::log::Level level, util::ConstevalFormatString< sizeof...(Args)> fmt, const Args &... args)
std::string ThreadGetInternalName()
Get the thread's internal (in-memory) name; used e.g.
SourceLocation source_loc
SystemClock::time_point timestamp
bool should_ratelimit
Hint for consumers if this entry should be ratelimited.
std::chrono::seconds mocktime
Structure and constant for tagging not to rate limit.
std::chrono::seconds GetMockTime()
For testing.