PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




Error Logging in PHP


Tutorials »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");
 }







A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting