开发者

are custom PHP logging and logging all possible errors mutually exclusive?

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜