mirror of
https://github.com/TomHarte/CLK.git
synced 2025-11-02 18:16:08 +00:00
Fix log entry interleaving.
This commit is contained in:
@@ -167,22 +167,24 @@ struct RepeatAccumulator {
|
|||||||
FILE *stream;
|
FILE *stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AccumulatingLog {
|
||||||
|
inline static thread_local RepeatAccumulator accumulator_;
|
||||||
|
};
|
||||||
|
|
||||||
template <Source source>
|
template <Source source>
|
||||||
struct LogLine<source, true> {
|
struct LogLine<source, true>: private AccumulatingLog {
|
||||||
public:
|
public:
|
||||||
explicit LogLine(FILE *const stream) noexcept :
|
explicit LogLine(FILE *const stream) noexcept :
|
||||||
stream_(stream) {}
|
stream_(stream) {}
|
||||||
|
|
||||||
~LogLine() {
|
~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) {
|
if(!accumulator_.last.empty()) {
|
||||||
// ++accumulator.count;
|
const char *const unadorned_prefix = prefix(accumulator_.source);
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(!accumulator.last.empty()) {
|
|
||||||
const char *const unadorned_prefix = prefix(accumulator.source);
|
|
||||||
std::string prefix;
|
std::string prefix;
|
||||||
if(unadorned_prefix) {
|
if(unadorned_prefix) {
|
||||||
prefix = "[";
|
prefix = "[";
|
||||||
@@ -190,17 +192,28 @@ public:
|
|||||||
prefix += "] ";
|
prefix += "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(accumulator.count > 1) {
|
if(accumulator_.count > 1) {
|
||||||
fprintf(accumulator.stream, "%s%s [* %zu]\n", prefix.c_str(), accumulator.last.c_str(), accumulator.count);
|
fprintf(
|
||||||
|
accumulator_.stream,
|
||||||
|
"%s%s [* %zu]\n",
|
||||||
|
prefix.c_str(),
|
||||||
|
accumulator_.last.c_str(),
|
||||||
|
accumulator_.count
|
||||||
|
);
|
||||||
} else {
|
} 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_.count = 1;
|
||||||
accumulator.last = output_;
|
accumulator_.last = output_;
|
||||||
accumulator.source = source;
|
accumulator_.source = source;
|
||||||
accumulator.stream = stream_;
|
accumulator_.stream = stream_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t size, typename... Args>
|
template <size_t size, typename... Args>
|
||||||
|
|||||||
Reference in New Issue
Block a user