mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE Moved Debug::get_rendered_backtrace() to SSBacktrace::get_rendered_backtrace() ENHANCEMENT Added SSLog, SSLogEmailWriter and SSLogErrorEmailFormatter for silverstripe message reporting API CHANGE Debug::send_errors_to() and Debug::send_warnings_to() are deprecated in favour of SSLog. See class documentation for SSLog on configuration of error email notifications MINOR Added SSLogTest for basic testing of the SSLog and SSLogEmailWriter classes git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84774 467b73ca-7a2a-4603-9d3b-597d59a354a9
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Sends an error message to an email whenever an error occurs
|
|
* in sapphire.
|
|
*
|
|
* @package sapphire
|
|
* @subpackage dev
|
|
*/
|
|
|
|
require_once 'Zend/Log/Writer/Abstract.php';
|
|
|
|
class SSLogEmailWriter extends Zend_Log_Writer_Abstract {
|
|
|
|
protected $emailAddress;
|
|
|
|
protected $customSmtpServer;
|
|
|
|
public function __construct($emailAddress, $customSmtpServer = false) {
|
|
$this->emailAddress = $emailAddress;
|
|
$this->customSmtpServer = $customSmtpServer;
|
|
}
|
|
|
|
/**
|
|
* Send an email to the designated emails set in
|
|
* {@link Debug::send_errors_to()}
|
|
*/
|
|
public function _write($event) {
|
|
// If no formatter set up, use the default
|
|
if(!$this->_formatter) {
|
|
$formatter = new SSLogErrorEmailFormatter();
|
|
$this->setFormatter($formatter);
|
|
}
|
|
|
|
$formattedData = $this->_formatter->format($event);
|
|
$subject = $formattedData['subject'];
|
|
$data = $formattedData['data'];
|
|
|
|
$originalSMTP = ini_get('SMTP');
|
|
// override the SMTP server with a custom one if required
|
|
if($this->customSmtpServer) ini_set('SMTP', $this->customSmtpServer);
|
|
|
|
mail($this->emailAddress, $subject, $data, "Content-type: text/html\nFrom: errors@silverstripe.com");
|
|
|
|
// reset the SMTP server to the original
|
|
if($this->customSmtpServer) ini_set('SMTP', $originalSMTP);
|
|
}
|
|
|
|
} |