0diff --git a/src/logging.cpp b/src/logging.cpp
1index e31e346549..006bac6a98 100644
2--- a/src/logging.cpp
3+++ b/src/logging.cpp
4@@ -74,8 +74,7 @@ bool BCLog::Logger::StartLogging()
5 // dump buffered messages from before we opened the log
6 m_buffering = false;
7 if (m_buffer_lines_discarded > 0) {
8- const auto source_loc{std::source_location::current()};
9- LogPrintStr_(strprintf("Early logging buffer overflowed, %d log lines discarded.\n", m_buffer_lines_discarded), source_loc, BCLog::ALL, Level::Info, /*should_ratelimit=*/false);
10+ LogPrintStr_(strprintf("Early logging buffer overflowed, %d log lines discarded.\n", m_buffer_lines_discarded), std::source_location::current(), BCLog::ALL, Level::Info, /*should_ratelimit=*/false);
11 }
12 while (!m_msgs_before_open.empty()) {
13 const auto& buflog = m_msgs_before_open.front();
14@@ -434,13 +433,13 @@ void BCLog::Logger::FormatLogStrInPlace(std::string& str, BCLog::LogFlags catego
15 str.insert(0, LogTimestampStr(now, mocktime));
16 }
17
18-void BCLog::Logger::LogPrintStr(std::string_view str, const std::source_location& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
19+void BCLog::Logger::LogPrintStr(std::string_view str, std::source_location&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
20 {
21 StdLockGuard scoped_lock(m_cs);
22- return LogPrintStr_(str, source_loc, category, level, should_ratelimit);
23+ return LogPrintStr_(str, std::move(source_loc), category, level, should_ratelimit);
24 }
25
26-void BCLog::Logger::LogPrintStr_(std::string_view str, const std::source_location& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
27+void BCLog::Logger::LogPrintStr_(std::string_view str, std::source_location&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
28 {
29 std::string str_prefixed = LogEscapeMessage(str);
30
31@@ -451,7 +450,7 @@ void BCLog::Logger::LogPrintStr_(std::string_view str, const std::source_locatio
32 .mocktime=GetMockTime(),
33 .str=str_prefixed,
34 .threadname=util::ThreadGetInternalName(),
35- .source_loc=source_loc,
36+ .source_loc=std::move(source_loc),
37 .category=category,
38 .level=level,
39 };
40diff --git a/src/logging.h b/src/logging.h
41index d588ef86dc..edef5c074f 100644
42--- a/src/logging.h
43+++ b/src/logging.h
44@@ -201,7 +201,7 @@ namespace BCLog {
45 std::list<std::function<void(const std::string&)>> m_print_callbacks GUARDED_BY(m_cs) {};
46
47 /** Send a string to the log output (internal) */
48- void LogPrintStr_(std::string_view str, const std::source_location& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
49+ void LogPrintStr_(std::string_view str, std::source_location&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
50 EXCLUSIVE_LOCKS_REQUIRED(m_cs);
51
52 std::string GetLogPrefix(LogFlags category, Level level) const;
53@@ -220,7 +220,7 @@ namespace BCLog {
54 std::atomic<bool> m_reopen_file{false};
55
56 /** Send a string to the log output */
57- void LogPrintStr(std::string_view str, const std::source_location& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
58+ void LogPrintStr(std::string_view str, std::source_location&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
59 EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
60
61 /** Returns whether logs will be written to any output */
62@@ -320,7 +320,7 @@ static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level leve
63 bool GetLogCategory(BCLog::LogFlags& flag, std::string_view str);
64
65 template <typename... Args>
66-inline void LogPrintFormatInternal(const std::source_location& source_loc, const BCLog::LogFlags flag, const BCLog::Level level, const bool should_ratelimit, util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
67+inline void LogPrintFormatInternal(std::source_location&& source_loc, const BCLog::LogFlags flag, const BCLog::Level level, const bool should_ratelimit, util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
68 {
69 if (LogInstance().Enabled()) {
70 std::string log_msg;
71@@ -329,7 +329,7 @@ inline void LogPrintFormatInternal(const std::source_location& source_loc, const
72 } catch (tinyformat::format_error& fmterr) {
73 log_msg = "Error \"" + std::string{fmterr.what()} + "\" while formatting log message: " + fmt.fmt;
74 }
75- LogInstance().LogPrintStr(log_msg, source_loc, flag, level, should_ratelimit);
76+ LogInstance().LogPrintStr(log_msg, std::move(source_loc), flag, level, should_ratelimit);
77 }
78 }
79
80diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp
81index 0043df182e..f5ce17aa23 100644
82--- a/src/test/logging_tests.cpp
83+++ b/src/test/logging_tests.cpp
84@@ -97,12 +97,12 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintStr, LogSetup)
85 std::source_location::current(),
86 std::source_location::current(),
87 };
88- LogInstance().LogPrintStr("foo1: bar1", source_locs[0], BCLog::LogFlags::NET, BCLog::Level::Debug, /*should_ratelimit=*/false);
89- LogInstance().LogPrintStr("foo2: bar2", source_locs[1], BCLog::LogFlags::NET, BCLog::Level::Info, /*should_ratelimit=*/false);
90- LogInstance().LogPrintStr("foo3: bar3", source_locs[2], BCLog::LogFlags::ALL, BCLog::Level::Debug, /*should_ratelimit=*/false);
91- LogInstance().LogPrintStr("foo4: bar4", source_locs[3], BCLog::LogFlags::ALL, BCLog::Level::Info, /*should_ratelimit=*/false);
92- LogInstance().LogPrintStr("foo5: bar5", source_locs[4], BCLog::LogFlags::NONE, BCLog::Level::Debug, /*should_ratelimit=*/false);
93- LogInstance().LogPrintStr("foo6: bar6", source_locs[5], BCLog::LogFlags::NONE, BCLog::Level::Info, /*should_ratelimit=*/false);
94+ LogInstance().LogPrintStr("foo1: bar1", std::move(source_locs[0]), BCLog::LogFlags::NET, BCLog::Level::Debug, /*should_ratelimit=*/false);
95+ LogInstance().LogPrintStr("foo2: bar2", std::move(source_locs[1]), BCLog::LogFlags::NET, BCLog::Level::Info, /*should_ratelimit=*/false);
96+ LogInstance().LogPrintStr("foo3: bar3", std::move(source_locs[2]), BCLog::LogFlags::ALL, BCLog::Level::Debug, /*should_ratelimit=*/false);
97+ LogInstance().LogPrintStr("foo4: bar4", std::move(source_locs[3]), BCLog::LogFlags::ALL, BCLog::Level::Info, /*should_ratelimit=*/false);
98+ LogInstance().LogPrintStr("foo5: bar5", std::move(source_locs[4]), BCLog::LogFlags::NONE, BCLog::Level::Debug, /*should_ratelimit=*/false);
99+ LogInstance().LogPrintStr("foo6: bar6", std::move(source_locs[5]), BCLog::LogFlags::NONE, BCLog::Level::Info, /*should_ratelimit=*/false);
100 std::ifstream file{tmp_log_path};
101 std::vector<std::string> log_lines;
102 for (std::string log; std::getline(file, log);) {