mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 02:40:14 +00:00
Logger: force color output if both out&err are term
Force color output if both stdout and stderr are connected to terminal. The setting is global and it is possible that only stdout is redirected (eg. to pager) while the check here was for clog (cerr) only. Thus escape sequences had been unintentionally output to the pipe.
This commit is contained in:
@@ -242,6 +242,24 @@ bool set_log_level(const char *optarg, bool *logger_repeat_msgs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Logger::preinit(bool skip_repeated)
|
||||
{
|
||||
Logger::skip_repeated = skip_repeated;
|
||||
if (rang::rang_implementation::supportsColor()
|
||||
&& rang::rang_implementation::isTerminal(std::cout.rdbuf())
|
||||
&& rang::rang_implementation::isTerminal(std::cerr.rdbuf())) {
|
||||
// force ANSI sequences even when written to ostringstream
|
||||
rang::setControlMode(rang::control::Force);
|
||||
#ifdef _WIN32
|
||||
// ANSI control sequences need to be explicitly set in Windows
|
||||
if (rang::rang_implementation::setWinTermAnsiColors(std::cout.rdbuf()) &&
|
||||
rang::rang_implementation::setWinTermAnsiColors(std::cerr.rdbuf())) {
|
||||
rang::setWinTermMode(rang::winTerm::Ansi);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
std::atomic<Logger::last_message *> Logger::last_msg{};
|
||||
bool Logger::skip_repeated = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user