mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-02 17:42:41 +00:00
Removing logError from CakeLog, it will be moved into ErrorHandler::handleError()
This commit is contained in:
parent
6c2c4f91df
commit
f373fc19d1
2 changed files with 4 additions and 66 deletions
|
@ -99,7 +99,7 @@ class CakeLog {
|
|||
* @return boolean success of configuration.
|
||||
* @throws Exception
|
||||
*/
|
||||
static function config($key, $config) {
|
||||
public static function config($key, $config) {
|
||||
if (empty($config['engine'])) {
|
||||
throw new Exception(__('Missing logger classname'));
|
||||
}
|
||||
|
@ -222,47 +222,4 @@ class CakeLog {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* An error_handler that will log errors to file using CakeLog::write();
|
||||
* You can control how verbose and what type of errors this error_handler will
|
||||
* catch using `Configure::write('log', $value)`. See core.php for more information.
|
||||
*
|
||||
*
|
||||
* @param integer $code Code of error
|
||||
* @param string $description Error description
|
||||
* @param string $file File on which error occurred
|
||||
* @param integer $line Line that triggered the error
|
||||
* @param array $context Context
|
||||
* @return void
|
||||
*/
|
||||
public static function logError($code, $description, $file = null, $line = null, $context = null) {
|
||||
switch ($code) {
|
||||
case E_PARSE:
|
||||
case E_ERROR:
|
||||
case E_CORE_ERROR:
|
||||
case E_COMPILE_ERROR:
|
||||
case E_USER_ERROR:
|
||||
$error = 'Fatal Error';
|
||||
$level = LOG_ERROR;
|
||||
break;
|
||||
case E_WARNING:
|
||||
case E_USER_WARNING:
|
||||
case E_COMPILE_WARNING:
|
||||
case E_RECOVERABLE_ERROR:
|
||||
$error = 'Warning';
|
||||
$level = LOG_WARNING;
|
||||
break;
|
||||
case E_NOTICE:
|
||||
case E_USER_NOTICE:
|
||||
$error = 'Notice';
|
||||
$level = LOG_NOTICE;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
$message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
|
||||
CakeLog::write($level, $message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,9 @@ class CakeLogTest extends CakeTestCase {
|
|||
$result = CakeLog::configured();
|
||||
$this->assertEqual($result, array('file'));
|
||||
|
||||
@unlink(LOGS . 'error.log');
|
||||
if (file_exists(LOGS . 'error.log')) {
|
||||
@unlink(LOGS . 'error.log');
|
||||
}
|
||||
CakeLog::write(LOG_WARNING, 'Test warning');
|
||||
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
||||
|
||||
|
@ -164,25 +166,4 @@ class CakeLogTest extends CakeTestCase {
|
|||
unlink(LOGS . 'error.log');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test logging with the error handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testLoggingWithErrorHandling() {
|
||||
@unlink(LOGS . 'debug.log');
|
||||
Configure::write('log', E_ALL & ~E_DEPRECATED);
|
||||
Configure::write('debug', 0);
|
||||
|
||||
set_error_handler(array('CakeLog', 'logError'));
|
||||
$out .= '';
|
||||
|
||||
$result = file(LOGS . 'debug.log');
|
||||
$this->assertEqual(count($result), 1);
|
||||
$this->assertPattern(
|
||||
'/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} Notice: Notice \(8\): Undefined variable:\s+out in \[.+ line \d+\]$/',
|
||||
$result[0]
|
||||
);
|
||||
@unlink(LOGS . 'debug.log');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue