Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding convenience methods for CakeLog

  • Loading branch information...
commit be9bcfd4b5da178ab142898b35b388a45fffc28c 1 parent 6040d96
@rchavik rchavik authored
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
View
45 lib/Cake/Log/CakeLog.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);
+ }
+
}
View
54 lib/Cake/Test/Case/Log/CakeLogTest.php
@@ -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();
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.