H I O X INDIA
FREE PHP Topics
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch Portuguese Japanese தமிழ்
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

PHP Topics
Introduction
Syntax
Data Types
Variables
Operators
Control Structures
Functions
Pre-defined Function
Calendar Functions
Date and Time
Array Functions
Array Functions List1
Array Functions List2
Math Functions
PHP Mysql Functions
File Handling
Error Handling
DB Size
PHP Mail
String Tokens
String Functions
String Functions List1
String Functions List2
Session Functions
Cookies Functions
Form Variables
Running PHP from JS
Array To JS
Array to PHP
Encryption
Common Header
Ask Your Doubts
More about PHP
Feedback





Error Logging in PHP


Topic

How to log php error in to system logger or a file?
or
I want a mail to be send on the occurance of a error?
or
How to send errors to a 3rd party logging system?



Explanation

Php's error_log() function will do this work of logging, mailing and redirecting error messages.
Consider that a database connection fails and so a error has to generated.

a) Send a message by mail: error_log("Your Message",1,"email id")
Log type "1" for error_log() function will be used for mailing.
Code Used: e.g:
//If mysql connection fails error_log will be called
if (!mysql_connect('localhost', 'mysql_user', 'mysql_password'))
  {
      error_log("connection fails", 1, "support@hioxindia.com");
     // Now when ever the connection fails a mail will be send to
     // "support@hioxindia.com".
}


b) Send a message to system logger: error_log("Your Message", 0)
Log type "0" for error_log function will be used for system logger.
Code Used: e.g:
//If mysql connection fails error_log will be called
if (!mysql_connect('localhost', 'mysql_user', 'mysql_password'))
 {
      error_log("My error message", 0);
     // as 0 is used, the system logger will be used
 }


c) Send a message to a ip and port: error_log("Your Message", 2, "ip:port")
Log type "2" for error_log function will be used for logging error messages in to a ip address.
Code Used: e.g:
//If mysql connection fails error_log will be called
if (!mysql_connect('localhost', 'mysql_user', 'mysql_password'))
 {
      error_log("My error message", 2, "127.0.0.1:4500");
     // as 2 is used, the log message will be send to the specified port of the ip.
 }


b) Adding error message in to a file: error_log("Your Message", 4, "filename")
Log type "4" for error_log will appended to the message to file specified.
Code Used: e.g:
//If mysql connection fails error_log will be called
if (!mysql_connect('localhost', 'mysql_user', 'mysql_password'))
 {
      error_log("My error message", 4, "/home/hscripts/error_log.txt");
 }






privacypolicy     licence     sitemap
© 2004-2010 HIOX INDIA