diff --git a/src/logging.h b/src/logging.h index 2ab21071a06..2b4b657dc9e 100644 --- a/src/logging.h +++ b/src/logging.h @@ -11,6 +11,7 @@ #include #include #include +#include // IWYU pragma: export #include #include @@ -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 00000000000..7ad548631a7 --- /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 +#include +#include + +/// 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