I want to save errors from a specific file in a custom file, Not the default file.
So I added that at the top of my script:
ini_set("log_errors", TRUE);
ini_set("error_log", get_template_directory_uri() . "/errors.log");
Then I removed a character from a function to create an error:
echo $date->fomat("F j, Y");
//Should be format("F j, Y")
That caused a fatal error:
Fatal error: Call to undefined method DateTime::fomat()
But I can't see any text in the log file.
I read a comment saying that ini_set
works only when the code is executed, So I have to edit that function in php.ini
.
But I want only to save that script errors in that custom file, Not all the errors, As I will parse that errors into a section on the website.
I can't use :
try {
//Script Here.
} catch (Exception $e) {
file_put_contents(get_template_directory_uri() . "/errors.log", $e->message);
}
Because that won't get all the fatal errors, Warnings and notices.
What to do then to get that script errors saved in a separate file?