Bootstrap: Allow WP_DEBUG_LOG to override the debug.log location.

Setting `WP_DEBUG_LOG` to a file path will now cause the debug log to be written to that file, rather than the default `WP_CONTENT_DIR/debug.log`.

Props SergeyBiryukov, ethitter, sebastian.pisula, nacin.
Fixes #18391.



git-svn-id: https://develop.svn.wordpress.org/trunk@44453 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-01-08 03:41:38 +00:00
parent 082c5d1534
commit b8413cc372

View File

@ -307,12 +307,13 @@ function timer_stop( $display = 0, $precision = 3 ) {
* from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY` * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
* as false will force errors to be hidden. * as false will force errors to be hidden.
* *
* When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content * When `WP_DEBUG_LOG` is true, errors will be logged to `wp-content/debug.log`.
* directory. * When `WP_DEBUG_LOG` is a valid path, errors will be logged to the specified file.
* *
* Errors are never displayed for XML-RPC, REST, and Ajax requests. * Errors are never displayed for XML-RPC, REST, and Ajax requests.
* *
* @since 3.0.0 * @since 3.0.0
* @since 5.1.0 `WP_DEBUG_LOG` can be a file path.
* @access private * @access private
*/ */
function wp_debug_mode() { function wp_debug_mode() {
@ -341,9 +342,17 @@ function wp_debug_mode() {
ini_set( 'display_errors', 0 ); ini_set( 'display_errors', 0 );
} }
if ( WP_DEBUG_LOG ) { if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) {
$log_path = WP_CONTENT_DIR . '/debug.log';
} elseif ( is_string( WP_DEBUG_LOG ) ) {
$log_path = WP_DEBUG_LOG;
} else {
$log_path = false;
}
if ( $log_path ) {
ini_set( 'log_errors', 1 ); ini_set( 'log_errors', 1 );
ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); ini_set( 'error_log', $log_path );
} }
} else { } else {
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR ); error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );