@ini_set('log_errors','On');
and
define('WP_DEBUG', true);
I'm trying to create a error log file , but i'm confusing about these two.
what kind of errors will get by log_errors
and WP_DEBUG
?
@ini_set('log_errors','On');
and
define('WP_DEBUG', true);
I'm trying to create a error log file , but i'm confusing about these two.
what kind of errors will get by log_errors
and WP_DEBUG
?
The define('WP_DEBUG_LOG', true);
will log errors into the debug.log file in the wp-content directory, @ini_set('log_errors','On');
allows you to specify the file where you want to save it. This should work for you:
@ini_set('log_errors', 1);
@ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */
@ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/your-error-file.log'); /* path to server-writable log file */
@ini_set( 'error_reporting', E_ALL ^ E_NOTICE ); /* the php parser to all errors, excreportept notices. */
The @ini_set('log_errors','On');
option sets the PHP handler to log errors. It is a general configuration option used to control script's behaviour. More on the function here
The define('WP_DEBUG', true);
on the other hand is very WP specific, it is used to capture and either print to screen / write to file WP specific errors. More on it here.
Writing to a log file
PHP stores error logs in /var/log/apache2
if PHP is an Apache2 module. Shared hosts are often store log files in your root directory /log
subfolder.
If you have access to a php.ini file you can specify the path like this:
error_log = /var/log/custom-logging-script.log
You can tell WP to log entries to a file by setting define( 'WP_DEBUG_LOG', true );
. That causes all errors to also be saved to a debug.log
log file inside the /wp-content/
directory.
If you quickly want to inspect a function or a variable then try something like this error_log($my_error, 3, "/var/tmp/my-errors.log");
. Its a handy function, more details here.
What you use depends on your requirement and what you want to debug.