When using WordPress, most people make error logs never come out in the production environment.
However, it is hard to have trouble when an error comes out.
So, although it is not well known, there is a setting to write an error in the log without outputting an error.
so let’s do it.
Easy to set in wp-config.php
Insert the following code into wp-config.php.
ini_set('display_errors', 0); define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false);
If you set the above settings, the log will be saved in the following location.
The contents of the log are as follows. It is familiar error information.
[08-Dec-2018 10:47:20 UTC] PHP Notice: Undefined variable: debug_information_first_activate_version in 【/sitepass/】wp-content/plugins/ultimate-gutenberg/admin/library/redux/options-init.php on line 482
However, there are two security concerns
This is fine, but this is not preferable, as it gives write privileges to the wp – content directory, and it will be accessed by the URL from the web and anyone will be able to see it.
Therefore, choose one of the two to improve security.
Take away the read permission
#wp-content/.htaccess Deny from all
Changing the location of the log file in its own way
ini_set('display_errors', 0); ini_set( 'log_errors', 1 ); ini_set( 'error_log', WP_CONTENT_DIR . '/【Log file location]】' ); define('WP_DEBUG', true); define( 'WP_DEBUG_DISPLAY', false ); define( 'WP_DEBUG_LOG', true );
(Extra) WP_DEBUG will also output extra errors
Incidentally, each code of WP_DEBUG introduced above will also output errors such as “Notice” which can be ignored .
If you want to output only Fatal errors and Warnings required during debugging, you can use the following code.
I am using this.
No, normally, WordPress logging function is not needed too much information.
ini_set('display_errors', 0); ini_set("log_errors", 1); ini_set( 'error_log', WP_CONTENT_DIR . '/【Log file location]】' ); define('WP_DEBUG', false);