Add scope to email logging.

This commit is contained in:
Jad Bitar 2013-02-15 02:46:10 +02:00 committed by mark_story
parent f46e00c7d9
commit f1b815a9bb
2 changed files with 36 additions and 2 deletions

View file

@ -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;
}

View file

@ -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
*