logging: check if output is a terminal only once

This commit is contained in:
Martin Piatka
2022-08-02 12:36:36 +02:00
parent c0a9db6d0f
commit 332000e4b8
2 changed files with 3 additions and 1 deletions

View File

@@ -382,4 +382,5 @@ thread_local std::string Log_output::buffer(initial_buf_size, '\0');
Log_output::Log_output(){
last_msg.reserve(initial_buf_size);
interactive = rang::rang_implementation::isTerminal(std::cout.rdbuf());
}

View File

@@ -170,6 +170,7 @@ private:
std::atomic<bool> skip_repeated;
log_timestamp_mode show_timestamps;
bool interactive = false;
/* Since writing to stdout uses locks internally anyway (C11 standard
* 7.21.2 sections 7&8), using a mutex here does not cause any significant
@@ -222,7 +223,7 @@ inline void Log_output::submit(){
const char *start_newline = "";
std::lock_guard<std::mutex> lock(mut);
if (skip_repeated && rang::rang_implementation::isTerminal(std::clog.rdbuf())) {
if (skip_repeated && interactive) {
if (buffer == last_msg) {
last_msg_repeats++;
printf(" Last message repeated %d times\r", last_msg_repeats);