Skip to content
Permalink
Browse files

Removing logError from CakeLog, it will be moved into ErrorHandler::h…

…andleError()
  • Loading branch information...
markstory committed Nov 15, 2010
1 parent 6c2c4f9 commit f373fc19d15bf717180577d8213b3bdcde32b490
Showing with 4 additions and 66 deletions.
  1. +1 −44 cake/libs/cake_log.php
  2. +3 −22 cake/tests/cases/libs/cake_log.test.php
@@ -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 @@ public static function write($type, $message) {
}
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 @@ function testConfig() {
$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 @@ function testLogFileWriting() {
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');
}
}

0 comments on commit f373fc1

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