Also, it still seems confusing to have two almost identical structs here and copy them field-by-field.
Why not just keep it a single blob?
diff --git a/src/logging.cpp b/src/logging.cpp
index abccc03abf..0de1f6030b 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -87,4 +87,4 @@ bool BCLog::Logger::StartLogging()
const auto& buflog = m_msgs_before_open.front();
- std::string s{buflog.str};
- FormatLogStrInPlace(s, buflog.category, buflog.level, buflog.source_loc, buflog.threadname, buflog.now, buflog.mocktime);
+ std::string s{buflog.message};
+ FormatLogStrInPlace(s, static_cast<LogFlags>(buflog.category), buflog.level, buflog.source_loc, buflog.thread_name, buflog.timestamp, buflog.mocktime);
m_msgs_before_open.pop_front();
@@ -374,7 +374,7 @@ std::string BCLog::Logger::GetLogPrefix(BCLog::LogFlags category, BCLog::Level l
-static size_t MemUsage(const BCLog::Logger::BufferedLog& buflog)
+static size_t MemUsage(const util::log::Entry& buflog)
{
- return memusage::DynamicUsage(buflog.str) +
- memusage::DynamicUsage(buflog.threadname) +
- memusage::MallocUsage(sizeof(memusage::list_node<BCLog::Logger::BufferedLog>));
+ return memusage::DynamicUsage(buflog.message) +
+ memusage::DynamicUsage(buflog.thread_name) +
+ memusage::MallocUsage(sizeof(memusage::list_node<util::log::Entry>));
}
@@ -442,13 +442,4 @@ void BCLog::Logger::LogPrint_(util::log::Entry entry)
{
- BufferedLog buf{
- .now = entry.timestamp,
- .mocktime = GetMockTime(),
- .str = std::move(str_prefixed),
- .threadname = std::move(entry.thread_name),
- .source_loc = entry.source_loc,
- .category = static_cast<LogFlags>(entry.category),
- .level = entry.level,
- };
- m_cur_buffer_memusage += MemUsage(buf);
- m_msgs_before_open.push_back(std::move(buf));
+ m_cur_buffer_memusage += MemUsage(entry);
+ m_msgs_before_open.push_back(std::move(entry));
}
diff --git a/src/logging.h b/src/logging.h
index b7d4a5f43b..bcd620d8ba 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -130,12 +130,2 @@ namespace BCLog {
{
- public:
- struct BufferedLog {
- SystemClock::time_point now;
- std::chrono::seconds mocktime;
- std::string str, threadname;
- SourceLocation source_loc;
- LogFlags category;
- Level level;
- };
-
private:
@@ -144,3 +134,3 @@ namespace BCLog {
FILE* m_fileout GUARDED_BY(m_cs) = nullptr;
- std::list<BufferedLog> m_msgs_before_open GUARDED_BY(m_cs);
+ std::list<util::log::Entry> m_msgs_before_open GUARDED_BY(m_cs);
bool m_buffering GUARDED_BY(m_cs) = true; //!< Buffer messages before logging can be started.
diff --git a/src/util/log.h b/src/util/log.h
index edf387e98b..c05751bf76 100644
--- a/src/util/log.h
+++ b/src/util/log.h
@@ -57,2 +57,3 @@ struct Entry {
SystemClock::time_point timestamp{SystemClock::now()};
+ std::chrono::seconds mocktime{GetMockTime()};
std::string thread_name{util::ThreadGetInternalName()};
And then going further and passing it to FormatLogStrInPlace?