0

I know that WordPress somehow with propers flags in wp-config.php direct errors to `error.log. I want to get notified when an error happens and logged in this file. I was going to monitor it, but if there is a way to hook into the error_log or something to accomplish this will be great.

The reason for this is that I want to submit these errors to third-party service. Thanks.

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Mar 11 at 18:31

1 Answer 1

1

WordPress tells PHP, using ini_set(), in wp_debug_mode() which errors should be handled and which file they should be written to. The function is called in wp-settings.php when WP is starting up.

As suggested by David in How to catch all PHP errors with custom error handler? answers you could use PHP's set_error_handler() to define a custom error handler for sending the errors to somewhere else.

Then there's the WP_Fatal_Error_Handler which WP attaches to PHP via register_shutdown_function() with wp_register_fatal_error_handler() - also in wp-settings.php.

Apparently the error handler can be extended, which means that you could use a child class to send the errors to the 3rd party service.

A drop-in ‘fatal-error-handler.php’ can be used to override the instance of this class and use a custom implementation for the fatal error handler that WordPress registers. The custom class should extend this class and can override its methods individually as necessary. The file must return the instance of the class that should be registered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.