Skip to content
Permalink
Browse files

adding convenience methods for CakeLog

  • Loading branch information...
rchavik committed May 10, 2012
1 parent 6040d96 commit be9bcfd4b5da178ab142898b35b388a45fffc28c
Showing with 99 additions and 0 deletions.
  1. +45 −0 lib/Cake/Log/CakeLog.php
  2. +54 −0 lib/Cake/Test/Case/Log/CakeLogTest.php
@@ -296,4 +296,49 @@ public static function write($type, $message, $scope = array()) {
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 @@ public function testScopedLogging() {
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();
}
}

0 comments on commit be9bcfd

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