How to turn on all error and warnings and log them to a file but to set up all of that within the script (not changing anything in php.ini). I want to define a file name and so that all errors and warnings get logged into it.
See
error_log
— Send an error message somewhere
Example
error_log("You messed up!", 3, "/var/tmp/my-errors.log");
You can customize error handling with your own error handlers to call this function for you whenever an error or warning or whatever you need to log occurs. For additional information, please refer to the Chapter Error Handling in the PHP Manual
Take a look at the log_errors
configuration option in php.ini. It seems to do just what you want to. I think you can use the error_log
option to set your own logging file too.
When the log_errors
option is enabled, any errors reported by PHP would be logged to the server log or the file specified with error_log
. You can set these options with ini_set
too, if you need to.
(Please not that display_errors
should be disabled in php.ini if this option is enabled)
Put the following code on the top of your file:
ini_set("log_errors", 1);
ini_set("error_log", "/path/to/php-error.log");
OR do it via php.ini file settings as follows: http://perishablepress.com/press/2008/01/30/advanced-php-error-handling-via-php/