move-only: Move SourceLocation to util/log.h
What changed, and why it matters
This commit is a simple code reorganization: it moves a small helper class called SourceLocation from one header file to a new, smaller header file. There is no change to how the software behaves, no bug fix, and no security-relevant change.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit creates src/util/log.h and moves the SourceLocation class from src/logging.h into it. src/logging.h now includes the new header via an IWYU export pragma. The class implementation is unchanged apart from clang-format reformatting. This is a pure refactor to reduce header dependencies for log-emitting code.
Changed components
src/logging.hsrc/util/log.hInspect captured patch +33 / −20
diff --git a/src/logging.h b/src/logging.h
index 2ab21071..2b4b657d 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -11,6 +11,7 @@
#include <tinyformat.h>
#include <util/check.h>
#include <util/fs.h>
+#include <util/log.h> // IWYU pragma: export
#include <util/string.h>
#include <util/time.h>
@@ -37,26 +38,6 @@ extern const char * const DEFAULT_DEBUGLOGFILE;
extern bool fLogIPs;
-/// Like std::source_location, but allowing to override the function name.
-class SourceLocation
-{
-public:
- /// The func argument must be constructed from the C++11 __func__ macro.
- /// Ref: https://en.cppreference.com/w/cpp/language/function.html#func
- /// Non-static string literals are not supported.
- SourceLocation(const char* func,
- std::source_location loc = std::source_location::current())
- : m_func{func}, m_loc{loc} {}
-
- std::string_view file_name() const { return m_loc.file_name(); }
- std::uint_least32_t line() const { return m_loc.line(); }
- std::string_view function_name_short() const { return m_func; }
-
-private:
- std::string_view m_func;
- std::source_location m_loc;
-};
-
struct SourceLocationEqual {
bool operator()(const SourceLocation& lhs, const SourceLocation& rhs) const noexcept
{
diff --git a/src/util/log.h b/src/util/log.h
new file mode 100644
index 00000000..7ad54863
--- /dev/null
+++ b/src/util/log.h
@@ -0,0 +1,32 @@
+// Copyright (c) The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_UTIL_LOG_H
+#define BITCOIN_UTIL_LOG_H
+
+#include <cstdint>
+#include <source_location>
+#include <string_view>
+
+/// Like std::source_location, but allowing to override the function name.
+class SourceLocation
+{
+public:
+ /// The func argument must be constructed from the C++11 __func__ macro.
+ /// Ref: https://en.cppreference.com/w/cpp/language/function.html#func
+ /// Non-static string literals are not supported.
+ SourceLocation(const char* func,
+ std::source_location loc = std::source_location::current())
+ : m_func{func}, m_loc{loc} {}
+
+ std::string_view file_name() const { return m_loc.file_name(); }
+ std::uint_least32_t line() const { return m_loc.line(); }
+ std::string_view function_name_short() const { return m_func; }
+
+private:
+ std::string_view m_func;
+ std::source_location m_loc;
+};
+
+#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.