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.


Built from https://develop.svn.wordpress.org/trunk@44453


git-svn-id: http://core.svn.wordpress.org/trunk@44284 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2019-01-08 03:42:48 +00:00
parent 5950f27205
commit 0049b17f8a
2 changed files with 14 additions and 5 deletions

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 );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.1-alpha-44452'; $wp_version = '5.1-alpha-44453';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.