5#ifndef BITCOIN_UTIL_LOG_H
6#define BITCOIN_UTIL_LOG_H
17#include <source_location>
30 std::source_location loc = std::source_location::current())
34 std::uint_least32_t
line()
const {
return m_loc.line(); }
64 SystemClock::time_point
timestamp{SystemClock::now()};
82template <
typename... Args>
89 log_msg =
"Error \"" + std::string{fmterr.what()} +
"\" while formatting log message: " + fmt.fmt;
94 .should_ratelimit = should_ratelimit,
95 .source_loc = std::move(source_loc),
96 .message = std::move(log_msg)});
99template <
typename... Args>
105template <
typename... Args>
119#define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__)
125#define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__)
126#define LogWarning(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Warning, __VA_ARGS__)
127#define LogError(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Error, __VA_ARGS__)
135#define detail_LogIfCategoryAndLevelEnabled(category, shouldlog, level, ...) \
137 if (shouldlog(category)) { \
138 detail_LogWithSrcLoc((category), (level), util::log::NO_RATE_LIMIT, __VA_ARGS__); \
143#define LogDebug(category, ...) detail_LogIfCategoryAndLevelEnabled(category, util::log::ShouldDebugLog, util::log::Level::Debug, __VA_ARGS__)
144#define LogTrace(category, ...) detail_LogIfCategoryAndLevelEnabled(category, util::log::ShouldTraceLog, util::log::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 Log(Entry entry)
Send message to be logged.
bool ShouldDebugLog(Category category)
Return whether messages with specified category should be debug logged.
bool ShouldTraceLog(Category 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.