fix: windows console may not have ansi color support

This commit is contained in:
Rachman Chavik 2012-07-02 21:19:02 +07:00
parent 31033239bd
commit 86a74e3887
2 changed files with 23 additions and 1 deletions

View file

@ -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) {

View file

@ -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']);
}
}