Login |  Register 
I think this organisation will be one of the big players of the future in the PHP world.
Darren
 

Logging

PHP comes with built in logging facilities. But why log problems? Well for anyone who has had to diagnose problems in a web application logging is essential, it allows you to cross reference when a problem occured with actually what happened in the code. Proper error handling and logging is therefore essential. One of the best ways to error log is to log errors when they are caught in a try catch block. We will discuss the easiest way to implement logging using the error_log function. The error_log function has the following format.
error_log($message, $message_type, $destination)
The desitination parameter is optional and depends on value of the message type parameter. The three types of message are: If message type 1 or 3 are chosen then the destination needs to be set, for message type 1 this will be a email address and for message type 3 it will be a path to a log file.
try
{
 /*
  * Error happens here
  */
}
catch (Exception $e)
{
 error_log("A problem occured, the error is: $e->getMessage(), 0);
}
Logging to the system log is better than nothing,. however you will have to find your applications messages from all the other messages inside the system log and there can be quite a lot. I usually prefer using a log dedicated just to my application.
try
{
 /*
  * Error happens here
  */
}
catch (Exception $e)
{
 error_log("A problem occured, the error is: $e->getMessage(), 3, "errors.log");
}
Finally for very serious errors you can use the email address, I tend to only do this for serious errors to help avoid a email box being flooded with more mundane problems, although ideally there should be no errors what so ever!
try
{
 /*
  * Error happens here
  */
}
catch (Exception $e)
{
 error_log("A problem occured, the error is: $e->getMessage(), 1, "errors@example.com");
}

Comments to date: 17. Page 1 of 2. Average Rating:
Hilakat Mafalia   3:44am on Friday, November 3rd, 2017 
good
UjK   3:41am on Friday, November 3rd, 2017 
LoL DREADFUL !!! .. what is this lol
gopal raiyani   11:34pm on Tuesday, March 14th, 2017 
good
Bhargav   12:02pm on Wednesday, March 8th, 2017 
The content is nice and straight but, Dude! you should work on the aesthetics...!
dffd   12:15am on Saturday, September 10th, 2016 
sdac
Karsen   1:33pm on Wednesday, January 27th, 2016 
I read your post and wished I'd wrtiten it
mozamil   4:53am on Tuesday, November 24th, 2015 
these lessons are very useful
Purnendu   7:40am on Tuesday, August 11th, 2015 
i can't undrstand
djcool9   2:55am on Tuesday, July 28th, 2015 
This site is throwing SQL exceptions in some events, well how it can solve our problems..... not agree with this site to learn
azahar   1:54am on Tuesday, May 19th, 2015 
website is not a helpfull for someone..


Page: -1-   2   

security image
Written by Dominic Skinner
Last Updated: 2011-10-25 16:00:38