EllisLab text mark
Advanced Search
     
Writing errors to database / emailing them
Posted: 19 August 2009 02:35 PM
Joined: 2008-11-09
37 posts

THis is driving me mad now.

Has anyone managed to extend CI’s error handling to write all errors to the database and email those bad boys to someone?

 
Posted: 19 August 2009 03:32 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2008-11-10
139 posts

You’ll have to paste more information if you expect an answer…
What is not working? Do you have code so far%

 Signature 

I
C I

 
Posted: 19 August 2009 03:36 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-11-09
37 posts

Well,

I would like to send any errors that occur in my application to a database table called errors which will allow me to monitor my application errors using reports.

I was wondering if anyone had extended or knew of an extension to allow this using CI’s existing error handling functions.

Thanks smile

 
Posted: 21 August 2009 06:43 AM   [ # 3 ]   [ Rating: 0 ]
Joined: 2009-08-19
16 posts

I am new here so there might be something easier, but I think you can easily just use a controller to write to the “log table” where you can record pretty much anything…

 
Posted: 21 August 2009 06:49 AM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-03
728 posts

Google solves—> Post on StackOverFlow.com:

Make a file MY_Exceptions.php and place it in /application/libraries/:

class MY_Exceptions extends CI_Exceptions {

    
function My_Exceptions()
    
{
        parent
::CI_Exceptions();
    
}

    
function log_exception($severity$message$filepath$line)

    
{   

        $severity 
= ( ! isset($this->levels[$severity])) ? $severity $this->levels[$severity];

        
log_message('error''Severity: '.$severity.'  --> '.$message' '.$filepath.' '.$lineTRUE);

        
$this->load->library('email');
        
$this->email->from('your@example.com''Your Name');
        
$this->email->to('someone@example.com');
        
$this->email->cc('another@another-example.com');
        
$this->email->bcc('them@their-example.com');

        
$this->email->subject('error');
        
$this->email->message('Severity: '.$severity.'  --> '.$message' '.$filepath.' '.$line);

        
$this->email->send();
    
}

Untested but might work smile

 Signature 

Blog - Twitter

DBlog

MeNeedz: Auth - Cloud - Password - Search - Shoutbox - Akismet -
Twitter - Visitor tracking

 
Posted: 06 November 2009 05:36 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-11-06
1 posts

add a table in your database as follows:

SET FOREIGN_KEY_CHECKS=0;
    -- ----------------------------
    -- 
Table structure for errores
    
-- ----------------------------
    
DROP TABLE IF EXISTS `errores`;
    
CREATE TABLE `errores` (
      `
idint(11NOT NULL auto_increment,
      `
Severityvarchar(50) default NULL,
      `
messagetext,
      `
filepathvarchar(250) default NULL,
      `
linevarchar(250) default NULL,
      
PRIMARY KEY  (`id`)
    ) 
ENGINE=MyISAM AUTO_INCREMENT=DEFAULT CHARSET=utf8

/system/libraries/Exceptions
modify the function log_exception($severity, $message, $filepath, $line) as this:
  add the following line:

$this->log_execption_db($severity$message$filepath$line); 

     
add the function log_execption_db to the system library

function log_execption_db($severity$message$filepath$line){
        $this
->ci =& get_instance();
        
$this->ci->load->database();
        
            
$data = array(
               
'Severity' => $severity ,
               
'message' => $message ,
               
'filepath' => $filepath,
               
'line' => $line
            
);

        
$this->ci->db->insert('errores'$data);
        
    

And “ya esta”, all the errors will be stored in database too. Also we could create a new confi item in our application to determines if we would like to stored the errors in DB, in file or in both.