6

I've been using set_error_handler to override the default php error handling with the sole purpose to have customized errors logging. but I've come to a conclusion that one simply can't have customized error logging and log all possible errors.

1) You can use set_error_handler() - but this function, quote from php manual:

following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT

So - by going this route - your customized log won't have these errors logged?

2) Second way is to use register_shutdown_function() and then run error_get_last() to get the the error... But - error_get_last() ... only gets the last error ... and while you might have multiple warnings and notices during script execution - this approach will only allow you to log the most recent error, notice, warning - right?

So - IMHO - I'm not seeing any way around this. Looks like if one wants to have the most complete error log - should just stick to default php logger - right?

2
  • what you mean by "customized errors logging"? just different logging format/place or some more logic depending on it? Commented Apr 12, 2011 at 19:59
  • well. I was going to save them into the database. but i haven't gotten to that point yet. Commented Apr 12, 2011 at 20:13

2 Answers 2

4

Second way is to use register_shutdown_function() and then run error_get_last() to get the the error... But - error_get_last()...only gets the last error

Right, but if it's an error type that killed the script, it would indeed be the correct error inside your shutdown function. Just in case, you can check the type key in the array that it returns for one of the catchable types. If it could have been caught by another error handler, take no action.

FWIW, I have never seen E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR or E_COMPILE_WARNING happen in the real world. Most compile errors are parse errors.

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

Comments

2

1) Thats correct. Its because this errors will stop the whole php-process from working properly and so it doesnt make much sense to allow the software to recover itself. However, if you write software, that breaks that hard, you have other problems than the logging.

2) Seems correct so far. But you also have set_error_handler() for this.

Comments

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.