PHP 5 Logging Error
What is a log?
A log is a text file saved on the web server. An Appropriate error message is appended to this file from the web server every time an error occurs. Error logs track every error or warning.
Errors can be logged using three different methods
- Set the error logging option manually in the php.ini file
- Set error logging option at runtime using error_log()
- Use of trigger_error()
Using error_log()
PHP provide the build in error) _log () logging any error when they occur. Using error log function message will be logged directly into log file at the web server rather than display to a browser.
Error_log function appends a user-defined error message into a log file which located on specified directory in the Web server.
Syntax
error_log( string, int type, destination, header);
Parameter of function
Parameter | Description |
Message | Error message that append into log file |
Type | Type of error message |
Extra header | Email Address |
Destination | File path |
Type of error message
Parameter | Description |
0 | This is the default option |
1 | The error message sent by the email |
2 | The error message is sent through the PHP debugging connection |
3 | The error message is appended to a destination file |
Solution of above problem
<?php $file = " data.txt "; If(is_file($file)) { echo "File is available"; } else error_log("file is not available",3,path/file name); ?>
If is_file return true that means file exist and if block executed.
If is_file function return false that means file does not exist then error_log() will log the error message in the log.txt.
Error Details

Error massege displayed
