Posted by Arjun on Sunday 23rd November 2014

Error reporting handling in Codeigniter

CodeIgniter default environment is development and so error reporting by default in turn on state, if you want to turn off reporting then change the environment value(in the top of the main index.php) to production or testing.

define('ENVIRONMENT', 'development'); // display_errors = ture, E_ALL 
define('ENVIRONMENT', 'development'); // display_errors = false, E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE 
define('ENVIRONMENT', 'development'); // display_errors = false, E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE

The above method will work with only For >= 2.x ci version. For < 2.x edit the top level index.php and adjust the error_reporting function to use E_ALL.Instead of E_ALL, you can change it to any of the predefined error constant.


Database Errors

The PHP errors are off, but any MySQL errors are still going to show. To turn these off , go to the application/config/database.php file and then Set the db_debug option to false:

$db['default']['db_debug'] = FALSE; 

So, if the error messages are hidden, how else can we tell if something is not working right? Well, CI can writes out any errors it encounters into its log file. 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'] .
Note: Make your /application/logs folder writable

  $config['log_threshold'] = 1;

Threshold options are: You can enable error logging by setting a threshold over zero. The threshold determines what gets logged. Threshold options are:

0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages

You can also pass in an array with threshold levels to show individual error types

array(2) = Debug Messages, without Error Messages

For a live site, you'll usually only enable Errors (1) to be logged otherwise your log files will fill up very fast.