Using Zend Expressive 2.0.5, I want to log PHP errors into the PHP's error log file itself, I went through https://docs.zendframework.com/zend-expressive/features/error-handling/#handling-exceptions-and-errors
I also saw this post: Zend expressive - php error reporting. Which cleared a lot of things for me but still quite didn't solve the asked question.
Things I did: Defined my own ErrorHandlerFactory
where I attached two listeners to the Zend-stratigility's ErrorHandler
First Listener uses Zend Log to log into my application's log file.(Just thought it would be nice to have errors in my application.log too.)
In the Second Listener, I want to log into PHP's error log file, so I have used
error_log()
method from php.
Questions:
The error_log() is not printing the log the way a log appears when printed by php's error handler. What I mean:
When an error is printed by the php's error handler, it looks something like this:
[08-Feb-2018 08:22:51 US/Central] PHP Warning: array_push() expects at least 2 parameters, 1 given in C:\webserver\webroot\myapi\src\App\src\Action\PageAction.php on line 38
While when I print the log using
error_log()
it looks something like this:[08-Feb-2018 09:03:49 US/Central] array_push() expects at least 2 parameters, 1 given in C:\webserver\webroot\myapi\src\App\src\Action\PageAction.php on line 38
What am I missing here is the PHP's error type: PHP Warning, Is this the error code? The error code I get is an integer, how do I parse that code? should I map the error codes with PHP errors constants which appear in the logs, for example: WARNING, NOTICE, etc, I can even do that, but the problem is: I got the same error code of 0 both the times when php's error handler printed a WARNING and a Fatal error logs.
Is it right to log errors in PHP's error log file like this? Should I do the job of PHP's error handler? The error handler could be doing a lot of things, for example: Logging the error message for few errors but for another also logging the stack trace. If this is not right, then how else can I send the error to the PHP's error_handler?
From my understanding:
My own Error Handler prevents users to look for exceptions and stack traces but rather returns a generic message. This also means that the Error Handler consumes the error and doesn't throw it further outside, i.e. will not throw it to the PHP's error handler.