Wednesday, July 4, 2012

PHP - Log error

In PHP language checking the logs and checking error is sometimes became difficult.
PHP is offer inbuild solution to log all errors to a log fiie.
First I will tell about creating the normal error log file.
Open your pho.ini file and modify the following line.
error_log = /var/log/php-error.log
Make sure display_errors set to Off (no errors to end users)
display_errors = Off
This is normal way to check the php error log.
But if you want to check where is script is dying or you want to debug.
Then use trigger_error() function. Personaly I love to use this function for logging the php errors.
Using this function you can specify the custom error messages as per your script requirement.
<?php
$test = ture;
if ($test == true) {
trigger_error("A custom error has been triggered");
}
?>
When you run this file and check the php error log file or you can check httpd/apache error log file.
you will got following error message.
Notice: A custom error has been triggered
in C:\webfolder\test.php on line 5

No comments:

Post a Comment