move-only: Move logging macros to util/log.h
What changed, and why it matters
This commit simply moves logging helper macros from one header file to another without changing what they do. It is a code organization cleanup with no security effect.
No action needed; this is a benign refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates the LogPrintLevel_, LogInfo, LogWarning, LogError, detail_LogIfCategoryAndLevelEnabled, LogDebug, and LogTrace macros from src/logging.h to src/util/log.h. The macro bodies and behavior are identical; only their source location changes. No functional or security-relevant change is introduced.
Changed components
src/logging.hsrc/util/log.hInspect captured patch +32 / −31
diff --git a/src/logging.h b/src/logging.h
index f9fddd5e..d41a33bc 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -318,35 +318,4 @@ inline void LogPrintFormatInternal(SourceLocation&& source_loc, BCLog::LogFlags
}
}
-// Allow __func__ to be used in any context without warnings:
-// NOLINTNEXTLINE(bugprone-lambda-function-name)
-#define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__)
-
-// Log unconditionally. Uses basic rate limiting to mitigate disk filling attacks.
-// Be conservative when using functions that unconditionally log to debug.log!
-// It should not be the case that an inbound peer can fill up a user's storage
-// with debug.log entries.
-#define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, /*should_ratelimit=*/true, __VA_ARGS__)
-#define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, /*should_ratelimit=*/true, __VA_ARGS__)
-#define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__)
-
-// Use a macro instead of a function for conditional logging to prevent
-// evaluating arguments when logging for the category is not enabled.
-
-// Log by prefixing the output with the passed category name and severity level. This logs conditionally if
-// the category is allowed. No rate limiting is applied, because users specifying -debug are assumed to be
-// developers or power users who are aware that -debug may cause excessive disk usage due to logging.
-#define detail_LogIfCategoryAndLevelEnabled(category, level, ...) \
- do { \
- if (LogAcceptCategory((category), (level))) { \
- bool rate_limit{level >= BCLog::Level::Info}; \
- Assume(!rate_limit);/*Only called with the levels below*/ \
- LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \
- } \
- } while (0)
-
-// Log conditionally, prefixing the output with the passed category name.
-#define LogDebug(category, ...) detail_LogIfCategoryAndLevelEnabled(category, BCLog::Level::Debug, __VA_ARGS__)
-#define LogTrace(category, ...) detail_LogIfCategoryAndLevelEnabled(category, BCLog::Level::Trace, __VA_ARGS__)
-
#endif // BITCOIN_LOGGING_H
diff --git a/src/util/log.h b/src/util/log.h
index f1d3bb26..ef5cbf14 100644
--- a/src/util/log.h
+++ b/src/util/log.h
@@ -43,4 +43,36 @@ namespace BCLog {
//! Alias for compatibility. Prefer util::log::Level over BCLog::Level in new code.
using Level = util::log::Level;
} // namespace BCLog
+
+// Allow __func__ to be used in any context without warnings:
+// NOLINTNEXTLINE(bugprone-lambda-function-name)
+#define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__)
+
+// Log unconditionally. Uses basic rate limiting to mitigate disk filling attacks.
+// Be conservative when using functions that unconditionally log to debug.log!
+// It should not be the case that an inbound peer can fill up a user's storage
+// with debug.log entries.
+#define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, /*should_ratelimit=*/true, __VA_ARGS__)
+#define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, /*should_ratelimit=*/true, __VA_ARGS__)
+#define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__)
+
+// Use a macro instead of a function for conditional logging to prevent
+// evaluating arguments when logging for the category is not enabled.
+
+// Log by prefixing the output with the passed category name and severity level. This logs conditionally if
+// the category is allowed. No rate limiting is applied, because users specifying -debug are assumed to be
+// developers or power users who are aware that -debug may cause excessive disk usage due to logging.
+#define detail_LogIfCategoryAndLevelEnabled(category, level, ...) \
+ do { \
+ if (LogAcceptCategory((category), (level))) { \
+ bool rate_limit{level >= BCLog::Level::Info}; \
+ Assume(!rate_limit); /*Only called with the levels below*/ \
+ LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \
+ } \
+ } while (0)
+
+// Log conditionally, prefixing the output with the passed category name.
+#define LogDebug(category, ...) detail_LogIfCategoryAndLevelEnabled(category, BCLog::Level::Debug, __VA_ARGS__)
+#define LogTrace(category, ...) detail_LogIfCategoryAndLevelEnabled(category, BCLog::Level::Trace, __VA_ARGS__)
+
#endif // BITCOIN_UTIL_LOG_H
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.