log php error in log file with trigger_error

log php error in log file with trigger_error

in this article i given full information about log php error in log file with trigger_error. PHP given the method for log error using there method.

log php error in log file with trigger_error

log php error in log file with trigger_error
log php error in log file with trigger_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

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “log php error in log file with trigger_error”

Leave a Reply

Your email address will not be published.