From f63069ab72defef98da3e34847a1016cbb36ac6d Mon Sep 17 00:00:00 2001 From: Marcus Müller Date: Sat, 28 Sep 2019 21:24:22 +0200 Subject: logging: On POSIX, don't use logging colors on non-tty --- host/lib/utils/log.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'host/lib') diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index 5a2af6603..b5c96867b 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,10 @@ constexpr double READ_TIMEOUT = 0.5; // Waiting time to read from the queue namespace { std::string verbosity_color(const uhd::log::severity_level& level) { + static const bool tty = uhd::is_a_tty(2); // is stderr a tty? + if (!tty) { + return ""; + } switch (level) { case (uhd::log::trace): return PURPLE; @@ -108,7 +113,7 @@ void console_log(const uhd::log::logging_info& log_info) << "[" << verbosity_name(log_info.verbosity) << "] " << "[" << log_info.component << "] " #ifdef UHD_LOG_CONSOLE_COLOR - << RESET_COLORS + << verbosity_color(uhd::log::off) // This will reset colors #endif << log_info.message << std::endl; } -- cgit v1.2.3