From 86a74e38871e8eec4c6dbb20ad6cf63462b38bea Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Mon, 2 Jul 2012 21:19:02 +0700 Subject: [PATCH] fix: windows console may not have ansi color support --- lib/Cake/Log/Engine/ConsoleLog.php | 7 ++++++- .../Test/Case/Log/Engine/ConsoleLogTest.php | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Log/Engine/ConsoleLog.php b/lib/Cake/Log/Engine/ConsoleLog.php index 24d4fab4d..255be190d 100644 --- a/lib/Cake/Log/Engine/ConsoleLog.php +++ b/lib/Cake/Log/Engine/ConsoleLog.php @@ -49,11 +49,16 @@ class ConsoleLog extends BaseLog { */ public function __construct($config = array()) { parent::__construct($config); + if (DS == '\\' && !(bool)env('ANSICON')) { + $outputAs = ConsoleOutput::PLAIN; + } else { + $outputAs = ConsoleOutput::COLOR; + } $config = Hash::merge(array( 'stream' => 'php://stderr', 'types' => null, 'scopes' => array(), - 'outputAs' => ConsoleOutput::COLOR, + 'outputAs' => $outputAs, ), $this->_config); $config = $this->config($config); if ($config['stream'] instanceof ConsoleOutput) { diff --git a/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php b/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php index 6db6bf8d1..e78682706 100644 --- a/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php +++ b/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php @@ -116,4 +116,21 @@ class ConsoleLogTest extends CakeTestCase { $this->assertContains($message, $logOutput); } +/** + * test default value of stream 'outputAs' + */ + public function testDefaultOutputAs() { + TestCakeLog::config('test_console_log', array( + 'engine' => 'TestConsoleLog', + )); + if (DS == '\\' && !(bool)env('ANSICON')) { + $expected = ConsoleOutput::PLAIN; + } else { + $expected = ConsoleOutput::COLOR; + } + $stream = TestCakeLog::stream('test_console_log'); + $config = $stream->config(); + $this->assertEquals($expected, $config['outputAs']); + } + }