mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Changes behaviour of _useLogger so that already-configured loggers are not overridden
This commit is contained in:
parent
0aa8847762
commit
153f04a976
2 changed files with 60 additions and 0 deletions
|
@ -964,15 +964,48 @@ class Shell extends Object {
|
|||
CakeLog::drop('stderr');
|
||||
return;
|
||||
}
|
||||
if (!$this->_loggerIsConfigured("stdout")) {
|
||||
$this->_configureStdOutLogger();
|
||||
}
|
||||
if (!$this->_loggerIsConfigured("stderr")) {
|
||||
$this->_configureStdErrLogger();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the stdout logger
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _configureStdOutLogger() {
|
||||
CakeLog::config('stdout', array(
|
||||
'engine' => 'Console',
|
||||
'types' => array('notice', 'info'),
|
||||
'stream' => $this->stdout,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the stderr logger
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _configureStdErrLogger() {
|
||||
CakeLog::config('stderr', array(
|
||||
'engine' => 'Console',
|
||||
'types' => array('emergency', 'alert', 'critical', 'error', 'warning', 'debug'),
|
||||
'stream' => $this->stderr,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given logger is configured
|
||||
*
|
||||
* @param string $logger The name of the logger to check
|
||||
* @return bool
|
||||
*/
|
||||
protected function _loggerIsConfigured($logger) {
|
||||
$configured = CakeLog::configured();
|
||||
return in_array($logger, $configured);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -920,6 +920,8 @@ TEXT;
|
|||
* @return void
|
||||
*/
|
||||
public function testFileAndConsoleLogging() {
|
||||
CakeLog::disable('stdout');
|
||||
CakeLog::disable('stderr');
|
||||
// file logging
|
||||
$this->Shell->log_something();
|
||||
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
||||
|
@ -944,6 +946,9 @@ TEXT;
|
|||
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
||||
$contents = file_get_contents(LOGS . 'error.log');
|
||||
$this->assertContains($this->Shell->testMessage, $contents);
|
||||
|
||||
CakeLog::enable('stdout');
|
||||
CakeLog::enable('stderr');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -995,4 +1000,26 @@ TEXT;
|
|||
public function testGetInvalidHelper() {
|
||||
$this->Shell->helper("tomato");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testShellLoggersDoNotGetOverridden()
|
||||
{
|
||||
$shell = $this->getMock("Shell", array(
|
||||
"_loggerIsConfigured",
|
||||
"configureStdOutLogger",
|
||||
"configureStdErrLogger",
|
||||
));
|
||||
|
||||
$shell->expects($this->any())
|
||||
->method("_loggerIsConfigured")
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$shell->expects($this->never())
|
||||
->method("_configureStdOutLogger");
|
||||
|
||||
$shell->expects($this->never())
|
||||
->method("_configureStdErrLogger");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue