Skip to content

Commit 64e1ddd

Browse files
committed
log: call LogPrint only once with time data samples
This prevents malformed log entries caused by other threads logging concurrently.
1 parent a8a272a commit 64e1ddd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/timedata.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <netaddress.h>
1212
#include <node/ui_interface.h>
1313
#include <sync.h>
14+
#include <tinyformat.h>
1415
#include <util/system.h>
1516
#include <util/translation.h>
1617
#include <warnings.h>
@@ -98,11 +99,12 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
9899
}
99100

100101
if (LogAcceptCategory(BCLog::NET)) {
102+
std::string log_message{"time data samples: "};
101103
for (const int64_t n : vSorted) {
102-
LogPrint(BCLog::NET, "%+d ", n); /* Continued */
104+
log_message += strprintf("%+d ", n);
103105
}
104-
LogPrint(BCLog::NET, "| "); /* Continued */
105-
LogPrint(BCLog::NET, "nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset / 60);
106+
log_message += strprintf("| median offset = %+d (%+d minutes)", nTimeOffset, nTimeOffset / 60);
107+
LogPrint(BCLog::NET, "%s\n", log_message);
106108
}
107109
}
108110
}

0 commit comments

Comments
 (0)