From 8f2384dbfc929f17e8990d83fc08136b9b39e638 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 10 Sep 2025 09:52:55 -0400 Subject: [PATCH] Fix log entry interleaving. --- Outputs/Log.hpp | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/Outputs/Log.hpp b/Outputs/Log.hpp index cd1b8543d..c7d75c55d 100644 --- a/Outputs/Log.hpp +++ b/Outputs/Log.hpp @@ -167,22 +167,24 @@ struct RepeatAccumulator { FILE *stream; }; +struct AccumulatingLog { + inline static thread_local RepeatAccumulator accumulator_; +}; + template -struct LogLine { +struct LogLine: private AccumulatingLog { public: explicit LogLine(FILE *const stream) noexcept : stream_(stream) {} ~LogLine() { - thread_local RepeatAccumulator accumulator; + if(output_ == accumulator_.last && source == accumulator_.source && stream_ == accumulator_.stream) { + ++accumulator_.count; + return; + } -// if(output_ == accumulator.last && source == accumulator.source && stream_ == accumulator.stream) { -// ++accumulator.count; -// return; -// } - - if(!accumulator.last.empty()) { - const char *const unadorned_prefix = prefix(accumulator.source); + if(!accumulator_.last.empty()) { + const char *const unadorned_prefix = prefix(accumulator_.source); std::string prefix; if(unadorned_prefix) { prefix = "["; @@ -190,17 +192,28 @@ public: prefix += "] "; } - if(accumulator.count > 1) { - fprintf(accumulator.stream, "%s%s [* %zu]\n", prefix.c_str(), accumulator.last.c_str(), accumulator.count); + if(accumulator_.count > 1) { + fprintf( + accumulator_.stream, + "%s%s [* %zu]\n", + prefix.c_str(), + accumulator_.last.c_str(), + accumulator_.count + ); } else { - fprintf(accumulator.stream, "%s%s\n", prefix.c_str(), accumulator.last.c_str()); + fprintf( + accumulator_.stream, + "%s%s\n", + prefix.c_str(), + accumulator_.last.c_str() + ); } } - accumulator.count = 1; - accumulator.last = output_; - accumulator.source = source; - accumulator.stream = stream_; + accumulator_.count = 1; + accumulator_.last = output_; + accumulator_.source = source; + accumulator_.stream = stream_; } template