diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 92446ff25..ade7921f8 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1066,10 +1066,15 @@ class CakeEmail { $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; } diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index e76b63750..89c2a23a9 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -1013,6 +1013,35 @@ class CakeEmailTest extends CakeTestCase { CakeLog::drop('email'); } +/** + * 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 *