From 0049b17f8a9c9ae7f5a855b8b24b508fa2878639 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 8 Jan 2019 03:42:48 +0000 Subject: [PATCH] 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 --- wp-includes/load.php | 17 +++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/wp-includes/load.php b/wp-includes/load.php index 26fef7240a..e959d79db8 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -307,12 +307,13 @@ function timer_stop( $display = 0, $precision = 3 ) { * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY` * as false will force errors to be hidden. * - * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content - * directory. + * When `WP_DEBUG_LOG` is true, errors will be logged to `wp-content/debug.log`. + * 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. * * @since 3.0.0 + * @since 5.1.0 `WP_DEBUG_LOG` can be a file path. * @access private */ function wp_debug_mode() { @@ -341,9 +342,17 @@ function wp_debug_mode() { 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( 'error_log', WP_CONTENT_DIR . '/debug.log' ); + ini_set( 'error_log', $log_path ); } } 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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index a8c7fba5e8..fc1ba44dd4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @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.