Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do error logging in CodeIgniter (PHP)

I want error logging in PHP CodeIgniter. How do I enable error logging?

I have some questions:

  1. What are all the steps to log an error?
  2. How is an error log file created?
  3. How to push the error message into log file (whenever an error occurs)?
  4. How do you e-mail that error to an email address?
like image 711
udaya Avatar asked Jul 09 '10 04:07

udaya


People also ask

How to enable php error reporting in CodeIgniter?

You can configure your CI log file by going to the config. php file in your applications/config directory and set value to $config['log_threshold'] . For a live site, you'll usually only enable Errors (1) to be logged otherwise your log files will fill up very fast.

How to disable error reporting in CodeIgniter?

No need to type a long query to disable error reporting in codeigniter. Use error_reporting(0); in the page to disable displaying errors in that page.

Where does Error_log write to?

There are two possible values for error_log: a custom log file and the syslog. If the syslog is used, then all PHP errors will be sent directly to the default system log file—in Linux, this is typically /var/log/syslog.


1 Answers

CodeIgniter has some error logging functions built in.

  • Make your /application/logs folder writable
  • In /application/config/config.php set
    $config['log_threshold'] = 1;
    or use a higher number, depending on how much detail you want in your logs
  • Use log_message('error', 'Some variable did not contain a value.');
  • To send an email you need to extend the core CI_Exceptions class method log_exceptions(). You can do this yourself or use this. More info on extending the core here

See http://www.codeigniter.com/user_guide/general/errors.html

like image 165
Keyo Avatar answered Sep 22 '22 13:09

Keyo