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 ?

LumberHack
  • 830
  • 10
  • 26
  • I know this is really old question. But hope this article help someone https://digitecz.com/web-development/how-to-debug-wordpress-using-browsers-javascript-console/ – Dushan Aug 29 '22 at 06:40

2 Answers2

2

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.  */
Grzegorz Pawlik
  • 2,198
  • 1
  • 18
  • 18
  • thank you for answering but in your code you did have code like `define('WP_DEBUG_LOG', true);` then how debug will work? –  Mar 24 '15 at 11:55
  • 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. – Grzegorz Pawlik Mar 24 '15 at 11:59
  • okay thank you, and i have another doubt if updating plugins , themes has any errors , this `log_errors ` will get them? –  Mar 24 '15 at 12:02
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.

LumberHack
  • 830
  • 10
  • 26