Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not color logs by default if stderr is not a tty #9290

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions base/loggers/loggers/Loggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
split->addChannel(log);
}

bool is_tty = isatty(STDIN_FILENO) || isatty(STDERR_FILENO);
bool should_log_to_console = isatty(STDIN_FILENO) || isatty(STDERR_FILENO);
bool color_logs_by_default = isatty(STDERR_FILENO);

if (config.getBool("logger.console", false)
|| (!config.hasProperty("logger.console") && !is_daemon && is_tty))
|| (!config.hasProperty("logger.console") && !is_daemon && should_log_to_console))
{
bool color_enabled = config.getBool("logger.color_terminal", true) && is_tty;
bool color_enabled = config.getBool("logger.color_terminal", color_logs_by_default);

Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(this, OwnPatternFormatter::ADD_NOTHING, color_enabled);
Poco::AutoPtr<DB::OwnFormattingChannel> log = new DB::OwnFormattingChannel(pf, new Poco::ConsoleChannel);
Expand Down