Skip to content
Permalink
Browse files

console: don't use colored output if there's no TTY

This prevents ANSI escape codes and style tags showing up in
cron-jobs, pipes or redirects.
  • Loading branch information...
mfn committed Sep 3, 2014
1 parent 638d2ea commit 0c55adebe0182ac0984952a5250539033899b0e0
Showing with 8 additions and 2 deletions.
  1. +4 −1 lib/Cake/Console/ConsoleOutput.php
  2. +4 −1 lib/Cake/Log/Engine/ConsoleLog.php
@@ -161,7 +161,10 @@ class ConsoleOutput {
public function __construct($stream = 'php://stdout') {
$this->_output = fopen($stream, 'w');
if (DS === '\\' && !(bool)env('ANSICON')) {
if (
(DS === '\\' && !(bool)env('ANSICON')) ||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
) {
$this->_outputAs = self::PLAIN;
}
}
@@ -48,7 +48,10 @@ class ConsoleLog extends BaseLog {
*/
public function __construct($config = array()) {
parent::__construct($config);
if (DS === '\\' && !(bool)env('ANSICON')) {
if (
(DS === '\\' && !(bool)env('ANSICON')) ||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
) {
$outputAs = ConsoleOutput::PLAIN;
} else {
$outputAs = ConsoleOutput::COLOR;

0 comments on commit 0c55ade

Please sign in to comment.
You can’t perform that action at this time.