Reputation: 27
I have this code here to create error log:
error_log(date("[Y-m-d H:i:s]:")." You messed up!", 3, "../my-errors.log");
Here, we can see the custom error 'You messed up!' that I have set to print in the error log. I don't want to use the custom error here. Instead of this I want to set the Errors/Warnings/Notices that are generated by PHP itself.
Is this possible and how can we do that?
Thankyou
Upvotes: 0
Views: 40
Reputation: 13549
if I understood it well, you're looking for error_get_last():
array error_get_last ( void )
error_get_last — Get the last occurred error. / Gets information about the last error that occurred.
Take a look:
$last_error = error_get_last();
$formated_last_error = sprintf('%s in %s on line %d'.PHP_EOL,
$last_error['message'], $last_error['file'], $last_error['line']);
error_log(date(DATE_ATOM) . $formated_last_error().PHP_EOL, 3, '/tmp/logs.log');
However, you should take a look at set_error_handler() function which is a general approach.
Upvotes: 1