If you are working on a CodeIgniter project and want to see the errors occurring in your project, then for this you have to enable error reporting in CodeIgniter project.
By default, CodeIgniter 4 is configured to display errors on the screen. However, for a production environment, it is advisable to enable error logging to capture and store errors in log files. To enable error reporting in the app/config/app.php file.
How to Check & Views Error Logs in CodeIgniter 4
Using the following methods, You can retrieve error logs from the log files programmatically or view them directly in a browser.
- Method 1: Programmatically Retrieving Error Logs
- Method 2: Viewing Error Logs in the Browser
Method 1: Programmatically Retrieving Error Logs
To retrieve error logs programmatically, you can use the Logger service. Inject the Logger class into your controller, model, or any other class where you want to access the logs, and utilize its methods like logError(), logCritical(), etc., to write custom error messages and retrieve the logs whenever necessary.
Method 2: Viewing Error Logs in the Browser
If you have set up the default error log location (writable/logs), you can access the log files directly through your browser by visiting the appropriate URL, such as http://example.com/writable/logs/log-{date}.log. Replace {date} with the specific log file date you want to view.
Conclusion
That’s all; In this tutorial, you have learned how to check and view error reporting log in codeigniter 4.