From 332000e4b84ca1096fe5b58e64be4ca83e9530bf Mon Sep 17 00:00:00 2001 From: Martin Piatka Date: Tue, 2 Aug 2022 12:36:36 +0200 Subject: [PATCH] logging: check if output is a terminal only once --- src/debug.cpp | 1 + src/debug.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/debug.cpp b/src/debug.cpp index 31a2cb6f6..3b035b343 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -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()); } diff --git a/src/debug.h b/src/debug.h index 9a9d62d11..894090a54 100644 --- a/src/debug.h +++ b/src/debug.h @@ -170,6 +170,7 @@ private: std::atomic 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 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);