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(); }
58 SystemClock::time_point
timestamp{SystemClock::now()};
78template <
typename... Args>
85 log_msg =
"Error \"" + std::string{fmterr.what()} +
"\" while formatting log message: " + fmt.fmt;
90 .should_ratelimit = should_ratelimit,
91 .source_loc = std::move(source_loc),
92 .message = std::move(log_msg)});
97#define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__)
103#define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, true, __VA_ARGS__)
104#define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, true, __VA_ARGS__)
105#define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, true, __VA_ARGS__)
113#define detail_LogIfCategoryAndLevelEnabled(category, level, ...) \
115 if (util::log::ShouldLog((category), (level))) { \
116 bool rate_limit{level >= BCLog::Level::Info}; \
117 Assume(!rate_limit); \
118 LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \
123#define LogDebug(category, ...) detail_LogIfCategoryAndLevelEnabled(category, BCLog::Level::Debug, __VA_ARGS__)
124#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.
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
std::chrono::seconds GetMockTime()
For testing.