4

@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 ?

1

2 Answers 2

3

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.  */
Sign up to request clarification or add additional context in comments.

3 Comments

thank you for answering but in your code you did have code like define('WP_DEBUG_LOG', true); then how debug will work?
WP_DEBUG_LOG is just an additional PHP constants that extend WP_DEBUG, you don't need to add it if you want to use your custom log file.
okay thank you, and i have another doubt if updating plugins , themes has any errors , this log_errors will get them?
2

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

  1. PHP

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
  1. WordPress

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.

  1. Alternately

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.