diff options
author | Marcus Müller <marcus.mueller@ettus.com> | 2019-09-28 21:24:22 +0200 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-10-09 07:41:23 -0700 |
commit | f63069ab72defef98da3e34847a1016cbb36ac6d (patch) | |
tree | e97cff0a89836144211198917373c0a79d250cd9 | |
parent | 3c38411bb69a4303a09ad2e158c902b5db2885fb (diff) | |
download | uhd-f63069ab72defef98da3e34847a1016cbb36ac6d.tar.gz uhd-f63069ab72defef98da3e34847a1016cbb36ac6d.tar.bz2 uhd-f63069ab72defef98da3e34847a1016cbb36ac6d.zip |
logging: On POSIX, don't use logging colors on non-tty
-rw-r--r-- | host/lib/utils/log.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
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 <uhd/utils/paths.hpp> #include <uhd/utils/static.hpp> #include <uhd/version.hpp> +#include <uhdlib/utils/isatty.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/make_shared.hpp> #include <atomic> @@ -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; } |