PHP - Log stacktrace for warnings?
There is an example of using set_error_handler()
in conjunction with ErrorException
to do just this:
https://php.net/manual/en/class.errorexception.php
You would just need to implement your custom logging functionality inside of the handler function.
UPDATE:
Note, this also works for warnings, and many other error types. For full compatibility, see the manual for set_error_handler()
:
https://php.net/set_error_handler
Just throw this at the start of your script:
set_error_handler(function($severity, $message, $file, $line) {
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
});
Remove the if
you want to log everything, even if it's suppressed.