Solution:1
Enable Debugging
You can simply enable debugging by adding the following code to your wp-config.php:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
There will be a debug.log file generated in your wp-content folder.
Usage in production environment
If you want to log the errors without printing them in the frontend, add the following line:
define( 'WP_DEBUG_DISPLAY', false );
This is really useful in production environments, since the page visitor will not be able to see your logs.
Printing errors
Now you can just write to your log by using the error_log function:
error_log( 'Hello World!' );
Or pretty print your output by making use of the print_r method:
error_log( print_r( 'Hello World!', true ) );
Pro Tip: If you’re using the bash you can observe the log with
tail -f wp-content/debug.log