Hi Dan,
thanks for awesome hook for codeigniter.
My story:
- i wanted to have UhOh enabled on localhost, but wanted to be disabled on real server, but i also wanted to have this kind of functionality : - when there is an error and codeigniter will log it, i added that codeigniter will insert log in database table error_logs (full message with filepath and so on…)and then send me email message about it (if there wasnt row in database with exactly same message - so i wont get duplicated emails about the same error).
- i did this with this code in application/core/MY_Exceptions.php:
function log_exception($severity, $message, $filepath, $line)
{
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
// Send a email if there isnt this error message yet - NOT ON LOCALHOST
if ($_SERVER['HTTP_HOST'] != 'localhost' AND $_SERVER['HTTP_HOST'] != '127.0.0.1') {
$CI =& get_instance();
$CI->load->helper('url');
$CI->load->database();
$email_message = "Message: ".$message."\nFilepath: ".$filepath." [".$line."]\nUrl: ".current_url();
$result = $CI->db->get_where('error_logy',array('sprava'=>$email_message));
if ($result->num_rows() == 0) {
$CI->load->library('email');
$CI->email->from('[email protected]', 'Bug logger');
$CI->email->to('[email protected]');
$CI->email->subject('Error on web example.com');
$CI->email->message($email_message);
$CI->email->send();
$CI->db->insert('error_logy',array('sprava'=>$email_message,'cas'=>date("Y-m-d H:i:s", time())));
}
}
}
but there was problem to add this in your MY_Exceptions.php, because in v1.5 you are using this code in constructor (so when we are in production, whole extension of core class Exceptions will be ignored (with my function for sending emails also)):
// If we are in production, then lets dump out now.
if (IN_PRODUCTION)
{
return;
}
So I had to change constructor to this:
public function __construct()
{
parent::__construct();
// If we are in production do nothing
if (IN_PRODUCTION)
{
}
else {
//Set the Exception Handler
set_exception_handler(array('MY_Exceptions', 'exception_handler'));
// Set the Error Handler
set_error_handler(array('MY_Exceptions', 'error_handler'));
// Set the handler for shutdown to catch Parse errors
register_shutdown_function(array('MY_Exceptions', 'shutdown_handler'));
// This is a hack to set the default timezone if it isn't set. Not setting it causes issues.
date_default_timezone_set(date_default_timezone_get());
}
}
and then added to beginning of each of your function this:
// If we are in production, then lets dump out now.
if (IN_PRODUCTION)
{
return;
}
As you can see - it isnt so good, its only fast hack. But i will be more than happy if you can implement similiar functionality (email reporting of errors) to UhOh! I think it isnt so complicated - you just let user posibility to set email_reporting to TRUE and if so, they will be forced to create simple database table (just like when you are using sessions with database).
You know, i dont want to tweek every new version of your UhOh to implement that functionality 😊
What do you think about it?
Sorry for my easy english, i hope you understand.