Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#10202 closed enhancement (fixed)

Enable display_errors if WP_DEBUG is true

Reported by: sivel's profile sivel Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8
Component: Warnings/Notices Keywords: has-patch commit
Focuses: Cc:

Description

Often enough when users enable WP_DEBUG they still do not get any good information because most hosts have display_errors set to Off and some times do not have access to the error logs.

Enabling display_errors when WP_DEBUG is true would make troubleshooting much easier.

We can add a constant for disabling display_errors for those people that would rather just have the errors sent to the globally defined error log file.

In addition we will add another constant to enable logging to a log file called debug.log.

New contants:

  • WP_DEBUG_DISPLAY - If not defined or defined as true it will set display_errors to On. If set to false it will set display_errors to Off. This sets the default behavior with WP_DEBUG to display errors.
  • WP_DEBUG_LOG - If defined and set to true this will log to a file in ABSPATH called debug.log. Set to false or do not define to disable logging to this file.

The above constants will only take effect if WP_DEBUG is defined and set to true.

Attachments (3)

10202.diff (821 bytes) - added by sivel 15 years ago.
10202.1.diff (864 bytes) - added by sivel 15 years ago.
Following the suggestions from Denis-de-Bernardy
10202.2.diff (1.0 KB) - added by sivel 15 years ago.
Reverting some of the logic and keep WP_CONTENT_DIR as the location of the debug.log

Download all attachments as: .zip

Change History (17)

#1 @sivel
15 years ago

  • Keywords has-patch commit added

@sivel
15 years ago

#2 @Denis-de-Bernardy
15 years ago

  • Keywords commit removed

you'r introducing a potential E_NOTICE or E_WARNING:

if ( ! defined('WP_DEBUG_DISPLAY') || WP_DEBUG_DISPLAY == true ) 

should be:

if ( ! defined('WP_DEBUG_DISPLAY') || defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY == true )


#3 @Denis-de-Bernardy
15 years ago

also:

        if ( defined('WP_DEBUG_LOG') && WP_DEBUG_LOG == true ) { 
 	209	                ini_set('log_errors', 1); 
 	210	                ini_set('error_log', ABSPATH . 'debug.log'); 
 	211	        } 

should probably go into WP_CONTENT_DIR (which usually is wrtiable as opposed to ABSPATH)

@sivel
15 years ago

Following the suggestions from Denis-de-Bernardy

#4 @dd32
15 years ago

if ( ! defined('WP_DEBUG_DISPLAY')
( defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY == true ) )

That can be simplified to this in line with the rest of core:

if ( ! defined('WP_DEBUG_DISPLAY') || WP_DEBUG_DISPLAY == true ) 

The == true isnt really needed either IMO.. but 'eh :)

+1 for WP_CONTENT_DIR instead of ABSPATH. Even though i think XMLRPC uses ABSPATH/.../rpc.log or something :)

#5 @dd32
15 years ago

actually, the uploads directory would be a better location..

#6 @Denis-de-Bernardy
15 years ago

how about we make WP_DEBUG_LOG contain the log file's location?

@sivel
15 years ago

Reverting some of the logic and keep WP_CONTENT_DIR as the location of the debug.log

#7 @sivel
15 years ago

  • Keywords commit added

DD32 and I agree that the location of the debug.log should be static so that it is located in the same place for everyone. We will not use the uploads dir, as at that point in the load we do not have access to that uploads dir location.

#8 follow-up: @azaozz
15 years ago

Wouldn't it be better to do:

if ( defined('WP_DEBUG_LOG') && WP_DEBUG_LOG ) { 
    ini_set('log_errors', 1); 
    ini_set('error_log', WP_CONTENT_DIR . '/debug.log'); 
} else {
    ini_set('display_errors', 1);
}

When debugging you'll want either one or the other.

#9 in reply to: ↑ 8 @sivel
15 years ago

Replying to azaozz:

Wouldn't it be better to do:

if ( defined('WP_DEBUG_LOG') && WP_DEBUG_LOG ) { 
    ini_set('log_errors', 1); 
    ini_set('error_log', WP_CONTENT_DIR . '/debug.log'); 
} else {
    ini_set('display_errors', 1);
}

When debugging you'll want either one or the other.

Well...what we are trying to achieve is to enable display_errors unless the user wants to disable them. And we only want to set the error_log if the user so specifies, that way logging can continue to go to the globally defined error_log and not force php to log to the debug.log in wp-content.

#10 follow-up: @jacobsantos
15 years ago

Yeah, you should look at BackPress and the Logger that exists in it.

#11 @jacobsantos
15 years ago

You guys are going about it the wrong way. Instead of trying to extend a hack, why not improve it to something actually worth while.

#12 in reply to: ↑ 10 @westi
15 years ago

Replying to jacobsantos:

Yeah, you should look at BackPress and the Logger that exists in it.

The BackPress logger is for logging your own info.

This is about logging php errors either to the page or to a file.

#13 @automattor
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11702]) Add extra site debugging support to enable conditionally enable display_errors or a special error_log. Fixes #10202 props sivel.

#14 @westi
15 years ago

  • Milestone changed from 2.8.2 to 2.9
Note: See TracTickets for help on using tickets.