I want error logging in PHP CodeIgniter. How do I enable error logging?
I have some questions:
- What are all the steps to log an error?
- How is an error log file created?
- How to push the error message into log file (whenever an error occurs)?
- How do you e-mail that error to an email address?
More oin regards to question part 4 How do you e-mail that error to an email address? The error_log function has email destination too. http://php.net/manual/en/function.error-log.php
Agha, here I found an example that shows a usage. Send errors message via email using error_log()
Also make sure that you have allowed codeigniter to log the type of messages you want in a config file.
i.e
$config['log_threshold'] = [log_level ranges 0-4];
CodeIgniter has some error logging functions built in.
$config['log_threshold'] = 1;
or use a higher number, depending on how much detail you want in your logs
log_message('error', 'Some variable did not contain a value.');
log_exceptions()
. You can do this yourself or use this. More info on extending the core hereSee http://www.codeigniter.com/user_guide/general/errors.html
To simply put a line in the server's error log, use PHP's error_log() function. However, that method will not send an e-mail.
First, to trigger an error:
By default, this will go in the server's error log file. See the ErrorLog directive for Apache. To set your own 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:
Please see the relevant PHP documentation for more info.