Software Development and QA Tips

Dev and QA Tips How to Log PHP Errors and Warnings Into a File?

How to Log PHP Errors and Warnings Into a File?

PHP Error Log | By Vakul Gotra | July 26, 2021
How to Log PHP Errors and Warnings Into a File?

A PHP application can generate different levels of errors and warnings during execution. It is important for QA engineers to see these errors in order to troubleshoot the application being tested. However, if you are having trouble displaying all the errors and warnings, you can use the following techniques to enable PHP errors and warnings.

1. Default Way

Use these lines to create logs:

ini_set("log_errors", 1);
ini_set("error_log", "/tmp/fervor.log");
error_log("Hello, errors!" );

The above code has created a log with Hello, errors! To verify, use the following command in cmd:

tail -f /tmp/fervor.log

Or

Update php.ini as described in this (Advanced PHP Error Handling via PHP)

2. Place the below-mentioned code in the index file on top:

error_reporting(E_ALL); // Error/Exception engine, always use E_ALL

ini_set('ignore_repeated_errors', TRUE); // always TRUE

ini_set('display_errors', FALSE); // Error/Exception display, FALSE in production environment or real server.TRUE in development environment

ini_set('log_errors', TRUE); // Error/Exception file logging engine.

ini_set('error_log', 'your/path/to/errors.log'); // Logging file path
error_log("Hello, errors!" );// to set your logs

Disclaimer

This publication is for informational purposes only and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.