how to log the php error in log file with trigger_error

Sponsors

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

Incoming search terms:

You may like following Articles!

This entry was posted in PHP, tutorials and tagged , , by Wordpress API. Bookmark the permalink.

About Wordpress API

API means Application Program interface. In Wordpress API we are giving all the information about wordpress API. We worked for many wordpress plugins and themes. We have expertise in PHP, Databases, Graphic Design, Ruby on Rails, Java, Wordpress, Drupal and many CMS. We always give you the best solutions about wordpress and other related topics in This Blog. We will give you always fresh tips and tricks and techniques about wordpress in this blog.

15 thoughts on “how to log the php error in log file with trigger_error

  1. Pingback: Tweets that mention how to log the php error in log file with trigger_error | Wordpressapi.com - Developer Code book -- Topsy.com

  2. Hi – I would like to say thank you for an interesting post about a subject I have had an interest in for a while now. I have been lurking and reading the comments avidly so just wanted to express my thanks for providing me with some very good reading material. I look forward to more, and taking a more proactive part in the discussions here, whilst learning too!!

  3. It is obvious that you love doing what you do as your excitement can be seen in all your work. Don’t ever let the passion die as we are here always looking forward to what you have in store for us. Thanks for your readiness to share your astonishing masterpieces.

  4. You write very detailed,Pay tribute to you.Couldn’t be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>