adding convenience methods for CakeLog

This commit is contained in:
Rachman Chavik 2012-05-10 22:52:52 +07:00
parent 6040d96710
commit be9bcfd4b5
2 changed files with 99 additions and 0 deletions

View file

@ -296,4 +296,49 @@ class CakeLog {
return true;
}
/**
* Convenience method to log error messages
*
* @return boolean Success
*/
public static function error($message) {
return self::write(LOG_ERROR, $message);
}
/**
* Convenience method to log warning messages
*
* @return boolean Success
*/
public static function warning($message) {
return self::write(LOG_WARNING, $message);
}
/**
* Convenience method to log notice messages
*
* @return boolean Success
*/
public static function notice($message) {
return self::write(LOG_NOTICE, $message);
}
/**
* Convenience method to log debug messages
*
* @return boolean Success
*/
public static function debug($message) {
return self::write(LOG_DEBUG, $message);
}
/**
* Convenience method to log info messages
*
* @return boolean Success
*/
public static function info($message) {
return self::write(LOG_INFO, $message);
}
}

View file

@ -429,4 +429,58 @@ class CakeLogTest extends CakeTestCase {
CakeLog::drop('shops');
}
/**
* test convenience methods
*/
public function testConvenienceMethods() {
@unlink(LOGS . 'error.log');
@unlink(LOGS . 'debug.log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('error', 'warning'),
'file' => 'error',
));
$testMessage = 'error message';
CakeLog::error($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
$this->assertContains($testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->_deleteLogs();
$testMessage = 'warning message';
CakeLog::warning($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
$this->assertContains($testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->_deleteLogs();
$testMessage = 'info message';
CakeLog::info($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
$this->assertContains($testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->_deleteLogs();
$testMessage = 'debug message';
CakeLog::debug($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
$this->assertContains($testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->_deleteLogs();
$testMessage = 'notice message';
CakeLog::notice($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
$this->assertContains($testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->_deleteLogs();
}
}