4

I want to know how I can display E_ERROR error messages to the screen but write E_ALL error messages to the error log, we currently use the error_reporting() in our app index page so we can change error reporting without the need to constantly restart the web server, but it seems that this (or perhaps the way it's meant to work) means that we only log errors that we see on the screen.

Is there a way to log and display different levels of errors?

Cheers!

1 Answer 1

1

You could make a custom error handler, and in your error handler check if the error is an E_ERROR; if so, print it out. Then log the error, regardless of whether it is an E_ERROR or not.

If you're not familiar with custom error handling, the PHP manual has a good example on how to use an error handler to do different things depending on the nature of a PHP error.

Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks, I'll have a look into this and get back to you :-)
Looking at the PHP manual it would appear this this does not work for the following error types E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, [and sometimes] E_STRICT, so this method won't work for me. It's a shame because it seemed like it was exactly what I wanted. Do you know of another method perhaps? Thanks for the suggestion anyway :-)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.