By default, this will go in the server's error log file. See the ErrorLog directive for Apache. To set your own log file:
ini_set('error_log', 'path/to/log/file');
Note that the log file you choose must already exist and be writable by the server process. The simplest way to make the file writable is to make the server user the owner of the file. (The server user may be nobody, _www, apache, or something else, depending on your OS distribution.)
To e-mail the error, you need to set up a custom error handler:
function mail_error($errno, $errstr, $errfile, $errline) {
$message = "[Error $errno] $errstr - Error on line $errline in file $errfile";
error_log($message); // writes the error to the log file
mail('you@yourdomain.com', 'I have an error', $message);
}
set_error_handler('mail_error', E_ALL^E_NOTICE);
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
In config.php add or edit the following lines to this:
------------------------------------------------------
$config['log_threshold'] = 4; // (1/2/3)
$config['log_path'] = '/home/path/to/application/logs/';
Run this command in the terminal:
----------------------------------
sudo chmod -R 777 /home/path/to/application/logs/