-
Notifications
You must be signed in to change notification settings - Fork 998
Closed
Labels
Description
Bug Report
- Yes, I reviewed the contribution guidelines.
- Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
Describe the current, buggy behavior
The WP_DEBUG_LOG
constant can be defined as a string in order to customize the log file path.
wp-cli completely ignores this case and always logs to WP_CONTENT_DIR . '/debug.log'.
Describe how other contributors can replicate this bug
Given I configure wordpress like this:
// wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', '/tmp/wordpress.log');
And I register the following command:
// register this somewhere
if (defined('WP_CLI')) {
\WP_CLI::add_command('log-test', function() {
trigger_error('This should log to /tmp/wordpress.log', E_USER_WARNING);
});
}
When I run the following commands in a shell:
export WP_CONTENT_DIR='/path/to/wp-content'
# Clear existing logs
echo '' > /tmp/wordpress.log
echo '' > "${WP_CONTENT_DIR}/debug.log"
# Run wp-cli
wp-cli.phar log-test
# Check log output
echo 'Logs to my custom log file ?'
grep -q 'PHP Warning' /tmp/wordpress.log && echo 'yes' || echo 'no'
echo 'Logs to the default log file ?'
grep -q 'PHP Warning' "${WP_CONTENT_DIR}/debug.log" && echo 'yes' || echo 'no'
Then I can see:
Logs to my custom log file ?
no
Logs to the default log file ?
yes
Describe what you expect as the correct outcome
The output of aforementioned steps should be:
Logs to my custom log file ?
yes
Logs to the default log file ?
no
Let us know what environment you are running this on
OS: Linux 5.9.0-2-amd64 #1 SMP Debian 5.9.6-1 (2020-11-08) x86_64
Shell:
PHP binary: /usr/local/bin/php
PHP version: 7.4.6
php.ini used:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /app
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config: /app/wp-cli.yml
WP-CLI version: 2.4.0
Provide a possible solution
The offending line should be changed to something like:
ini_set( 'error_log', is_string(WP_DEBUG_LOG) ? WP_DEBUG_LOG : WP_CONTENT_DIR . '/debug.log' );
janboddez