0

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

1
  • 4
    If you want to log PHP's regular errors / warnings, then just enable php logging. They are already probably being logged to a directory like /var/log/apache/error.log. Or just change the directory if you want to log it to a custom file: stackoverflow.com/questions/3531703/… Commented Nov 16, 2017 at 9:52

1 Answer 1

1

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.