Created
September 3, 2011 20:58
-
-
Save isaiahdw/1191785 to your computer and use it in GitHub Desktop.
Email Log writer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Log_email extends Log_Writer { | |
/** | |
* Email the log message to the website administrator. | |
* | |
* @param array messages | |
* @return void | |
*/ | |
public function write(array $messages) | |
{ | |
try | |
{ | |
$body = ''; | |
foreach ($messages as $message) | |
{ | |
$body .= PHP_EOL.$message['time'].' --- '.$this->_log_levels[$message['level']].': '.$message['body']; | |
} | |
// You probably want to load these from a config | |
$message = array( | |
'from' => 'application_name@example.com', | |
'recipients' => 'errors@example.com', | |
'subject' => 'Error Message from Application Name', | |
'message' => $body, | |
); | |
// You can send the email here however you normally do it in your application | |
Email::send($message['recipients'], $message['from'], $message['subject'], $message['message'], FALSE); | |
} | |
catch (Exception $e) | |
{ | |
// Nothing we can do.... | |
} | |
} | |
} // End Log_Email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, its working for me.