Is it possible to log stacktraces for php warnings? Or catch a warning and error_log() it?
There’s some code causing warnings in my error log, but it’s impossible to know what’s causing these warnings without knowing the stack trace.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is an example of using
set_error_handler()in conjunction withErrorExceptionto 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