f69d1ae util/log: Provide util::log::NO_RATE_LIMIT to avoid rate limits:
nit: I find it a bit confusing that after the existing *Internal suffix, this adds another internal marker via the trailing _.
Could we hide the helper behind a util::log::detail namespace instead? For example, the bool-taking helper could be renamed to LogPrintFormat, while the macro-facing overloads stay as
LogPrintFormatInternal under util::log::detail. That would make the implementation boundary explicit without suffix stacking.
diff --git a/src/util/log.h b/src/util/log.h
--- a/src/util/log.h (revision 02b2c41103435d8dbaa77a526e484066471b2b8c)
+++ b/src/util/log.h (revision 7d96b8db4fa1f1e4190aa22ae1a328f52a4c637f)
@@ -79,8 +79,10 @@
/** Send message to be logged. Applications using the logging library need to provide this. */
void Log(Entry entry);
+namespace detail {
+
template <typename... Args>
-inline void LogPrintFormatInternal_(SourceLocation&& source_loc, BCLog::LogFlags flag, util::log::Level level, bool should_ratelimit, util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
+inline void LogPrintFormat(SourceLocation&& source_loc, BCLog::LogFlags flag, util::log::Level level, bool should_ratelimit, util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
{
std::string log_msg;
try {
@@ -99,14 +101,16 @@
template <typename... Args>
inline void LogPrintFormatInternal(SourceLocation&& source_loc, BCLog::LogFlags flag, util::log::Level level, util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
{
- return LogPrintFormatInternal_(std::move(source_loc), flag, level, /*should_ratelimit=*/true, fmt, args...);
+ return LogPrintFormat(std::move(source_loc), flag, level, /*should_ratelimit=*/true, fmt, args...);
}
template <typename... Args>
inline void LogPrintFormatInternal(SourceLocation&& source_loc, BCLog::LogFlags flag, util::log::Level level, util::log::NoRateLimitTag, util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
{
- return LogPrintFormatInternal_(std::move(source_loc), flag, level, /*should_ratelimit=*/false, fmt, args...);
+ return LogPrintFormat(std::move(source_loc), flag, level, /*should_ratelimit=*/false, fmt, args...);
}
+
+} // namespace detail
} // namespace util::log
namespace BCLog {
@@ -116,7 +120,7 @@
// Allow __func__ to be used in any context without warnings:
// NOLINTNEXTLINE(bugprone-lambda-function-name)
-#define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__)
+#define detail_LogWithSrcLoc(category, level, ...) util::log::detail::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__)
// Log unconditionally. Uses basic rate limiting to mitigate disk filling attacks.
// Be conservative when using functions that unconditionally log to debug.log!