5

I'm writing a simple error handling using set_exception_handler(...). Everything works fine, but the default exception logging to the syslog seems to get disabled, when I use the set_exception_handler(...) and log exceptions in my custom file.

For the logging of "non-Trowables" there is a function set_error_handler. If the handler function returns false, the normal error handler continues, that means the original PHP error message is stored to the system log. For the exception handler no return value is provided.

How to store the original PHP error message to the system log, after the set_exception_handler(...)'s callback has been executed?

automatix
  • 14,018
  • 26
  • 105
  • 230
  • 2
    There's no native way of doing this as far as I'm aware, but there's a workaround using a custom ExceptionHandler's `__destruct()` method here: http://stackoverflow.com/questions/7856173/throwing-exception-within-exception-handler – iainn May 19 '16 at 11:58
  • 1
    Thank you for the comment! Yes, this workaround works. One should may not forgot to set `display_errors` to `0` (in production). Another workaround is [`error_log(...)`](http://php.net/manual/en/function.error-log.php). – automatix May 19 '16 at 12:30
  • Actually even no `__destruct()` is needed -- the `throw` or the `error_log(...)` can simply be executed somewhere at the end of the handler callback. – automatix May 19 '16 at 12:39

0 Answers0