Created
April 3, 2012 13:54
-
-
Save a-chernykh/2292191 to your computer and use it in GitHub Desktop.
CodeIgniter error notifications
This file contains hidden or 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 | |
class MY_Exceptions extends CI_Exceptions { | |
function My_Exceptions() | |
{ | |
parent::CI_Exceptions(); | |
} | |
function show_error($heading, $message, $template = 'error_general', $status_code = 500) | |
{ | |
if ($status_code == 500) | |
{ | |
$this->_report_error($message); | |
} | |
return parent::show_error($heading, $message, $template = 'error_general', $status_code = 500); | |
} | |
function log_exception($severity, $message, $filepath, $line) | |
{ | |
parent::log_exception($severity, $message, $filepath, $line); | |
if ($severity != E_WARNING && $severity != E_NOTICE && $severity != E_STRICT) | |
{ | |
$this->_report_error($message); | |
} | |
} | |
function _get_debug_backtrace($br = "<BR>") { | |
$trace = array_slice(debug_backtrace(), 3); | |
$msg = '<code>'; | |
foreach($trace as $index => $info) { | |
if (isset($info['file'])) | |
{ | |
$msg .= $info['file'] . ':' . $info['line'] . " -> " . $info['function'] . '(' . $info['args'] . ')' . $br; | |
} | |
} | |
$msg .= '</code>'; | |
return $msg; | |
} | |
function _report_error($subject) | |
{ | |
$CI =& get_instance(); | |
$CI->load->library('email'); | |
$body = ''; | |
$body .= 'Request: <br/><br/><code>'; | |
foreach ($_REQUEST as $k => $v) { | |
$body .= $k . ' => ' . $v . '<br/>'; | |
} | |
$body .= '</code>'; | |
$body .= '<br/><br/>Server: <br/><br/><code>'; | |
foreach ($_SERVER as $k => $v) { | |
$body .= $k . ' => ' . $v . '<br/>'; | |
} | |
$body .= '</code>'; | |
$body .= '<br/><br/>Stacktrace: <br/><br/>'; | |
$body .= $this->_get_debug_backtrace(); | |
$CI->email->from('[email protected]', '[MyApp production] MyApp Notifier'); | |
$CI->email->to('[email protected]'); | |
$CI->email->subject($subject); | |
$CI->email->message($body); | |
$CI->email->send(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment