mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
adding convenience methods for CakeLog
This commit is contained in:
parent
6040d96710
commit
be9bcfd4b5
2 changed files with 99 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue