silverstripe-framework/dev/SSLogEmailWriter.php
Sean Harvey 2cca0b0a7b API CHANGE Added SSLogFileWriter to replace Debug::log_errors_to() and Debug::log_error_if_necessary() - the existing formatting for the Debug deprecation functions is now wrapped into SSLogErrorFileFormatter
MINOR Moved SSErrorLogTest to SSLogTest
MINOR Documentation updates for SSLog and other bits and pieces



git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84828 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-08-19 21:55:03 +00:00

50 lines
1.3 KiB
PHP

<?php
/**
* Sends an error message to an email whenever an error occurs
* in sapphire.
*
* @see SSLog for more information on using writers.
*
* @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 email address set in
* this writer.
*/
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);
}
}