Skip to content

Instantly share code, notes, and snippets.

@isaiahdw
Created September 3, 2011 20:58
Show Gist options
  • Save isaiahdw/1191785 to your computer and use it in GitHub Desktop.
Save isaiahdw/1191785 to your computer and use it in GitHub Desktop.
Email Log writer
<?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
@nexeck
Copy link

nexeck commented Sep 5, 2011

Thank you, its working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment