Permalink
Browse files

Add scope to email logging.

  • Loading branch information...
1 parent f46e00c commit f1b815a9bbc9d58e09da9bab4f2110c643baa814 @jadb jadb committed with markstory Feb 15, 2013
Showing with 36 additions and 2 deletions.
  1. +7 −2 lib/Cake/Network/Email/CakeEmail.php
  2. +29 −0 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -1066,10 +1066,15 @@ public function send($content = null) {
$contents = $this->transportClass()->send($this);
if (!empty($this->_config['log'])) {
$level = LOG_DEBUG;
+ $scope = 'email';
if ($this->_config['log'] !== true) {
- $level = $this->_config['log'];
+ if (!is_array($this->_config['log'])) {
+ $this->_config['log'] = array('level' => $this->_config['log']);
+ }
+ $this->_config['log'] = array_merge(compact('level', 'scope'), $this->_config['log']);
+ extract($this->_config['log']);
}
- CakeLog::write($level, PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message']);
+ CakeLog::write($level, PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message'], $scope);
}
return $contents;
}
@@ -1014,6 +1014,35 @@ public function testSendWithLog() {
}
/**
+ * testSendWithLogAndScope method
+ *
+ * @return void
+ */
+ public function testSendWithLogAndScope() {
+ CakeLog::config('email', array(
+ 'engine' => 'FileLog',
+ 'path' => TMP,
+ 'types' => array('cake_test_emails'),
+ 'scopes' => array('email')
+ ));
+ CakeLog::drop('default');
+ $this->CakeEmail->transport('Debug');
+ $this->CakeEmail->to('me@cakephp.org');
+ $this->CakeEmail->from('cake@cakephp.org');
+ $this->CakeEmail->subject('My title');
+ $this->CakeEmail->config(array('log' => array('level' => 'cake_test_emails', 'scope' => 'email')));
+ $result = $this->CakeEmail->send("Logging This");
+
+ App::uses('File', 'Utility');
+ $File = new File(TMP . 'cake_test_emails.log');
+ $log = $File->read();
+ $this->assertTrue(strpos($log, $result['headers']) !== false);
+ $this->assertTrue(strpos($log, $result['message']) !== false);
+ $File->delete();
+ CakeLog::drop('email');
+ }
+
+/**
* testSendRender method
*
* @return void

0 comments on commit f1b815a

Please sign in to comment.