From 389627ff73a60b5f6b48ed1b348fdc59e9713b1f Mon Sep 17 00:00:00 2001 From: Ivan Chikish Date: Mon, 10 Jul 2023 04:58:21 +0300 Subject: [PATCH] [Logs] Print colors only on TTY --- orbis-kernel/src/utils/Logs.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/orbis-kernel/src/utils/Logs.cpp b/orbis-kernel/src/utils/Logs.cpp index 06fdae3aa..84a0e08c7 100644 --- a/orbis-kernel/src/utils/Logs.cpp +++ b/orbis-kernel/src/utils/Logs.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include static void append_hex(std::string &out, std::uintmax_t value) { @@ -226,6 +227,11 @@ void _orbis_log_print(LogLevel lvl, const char *msg, std::string_view names, break; } - std::fprintf(stderr, "%s%s\e[0m\n", color, text.c_str()); + static const bool istty = isatty(fileno(stderr)); + if (istty) { + std::fprintf(stderr, "%s%s\e[0m\n", color, text.c_str()); + } else { + std::fprintf(stderr, "%s\n", text.c_str()); + } } } // namespace orbis::logs