I'm trying to use error_log()
in a custom WordPress plugin I am building but for some reason, I can't.
When I use error_log()
my site just breaks, but I'm not seeing any errors in debug.log
.
I have setup debugging in my wp_config.php
file like this:
define('WP_DEBUG', true); define('WP_DEBUG_LOG', true);
Stranegly, if I use error_log()
in my theme, the site doesn't break, but nothing is output to debug.log
either.
What do I need to do to be able to use error_log()
in my WordPress plugin and theme?
I'm using WordPress 3.9.1.
Printing errors php fixed the error logging. Setting WP_DEBUG_DISPLAY to false removed the errors from the browser but allowed them to be output in the log. It would seem that Wordpress requires define('WP_DEBUG_DISPLAY'); to output errors to the log whether you set it to be true or false . Show activity on this post.
WordPress comes with a debugging system that can log any error messages displayed on your site. This can help you discover and fix problems on your website.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With