当 WP_DEBUG_LOG 设置为 true 时,debug.log 中没有显示调试输出,为什么?

问题描述 投票:0回答:3

我正在尝试使用 WordPress 为我正在开发的插件启用基本调试输出。到目前为止我设法得到了一些,但未能将其重定向到

wp-content/debug.log
。我一直在大致遵循 Douglas Neiner 的指南。这就是我所做的:

我将这段代码添加到

wp-config.php
的末尾:

@ini_set ('display_errors', 0);
define ('WP_DEBUG', true);
define ('WP_DEBUG_DISPLAY', false);
define ('WP_DEBUG_LOG', true);

我手动创建了

debug.log
文件并确保
www-data
用户可以访问它(我在 Ubuntu 12.04 上本地运行 WordPress):

septi@norbert:~$ sudo su www-data -c 'ls -l /usr/share/wordpress/wp-content/debug.log'
-rw-rw-r-- 1 root www-data 0 Dec  9 22:12 /usr/share/wordpress/wp-content/debug.log
septi@norbert:~$ sudo su www-data -c 'ls -l /srv/www/localhost/wp-content/debug.log'
-rw-rw-r-- 1 root www-data 0 Dec  9 22:12 /srv/www/localhost/wp-content/debug.log
septi@norbert:~$ sudo su www-data -c 'echo i can write >> /usr/share/wordpress/wp-content/debug.log'
septi@norbert:~$

在插件激活挂钩内添加了一些假定的调试输出语句,以及故意错误:

include ('i fail wp');

register_activation_hook (__FILE__, 'hello_world_activate');

function hello_world_activate()
{
    error_log ('I love debug output when it works!');
}

我期望的是关于

debug.log
中缺少包含文件的错误消息以及“我喜欢它工作时的调试输出!”消息,页面上没有任何内容。我得到的是页面消息中缺少包含文件,而
debug.log
中没有任何内容。然而,调试输出消息并未完全丢失。我在
/var/log/apache2/error.log
中找到了它:

[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning:  include(i fail wp): failed to open stream: No such file or directory in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning:  include(): Failed opening 'i fail wp' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] I love debug output when it works!, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning:  include(i fail wp): failed to open stream: No such file or directory in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning:  include(): Failed opening 'i fail wp' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=

我怀疑

error_log()
函数不适合用于输出到
debug.log
,但我未能找到正确的方法。哦,当然我可以硬编码文件路径并附加到它,但是,你知道......

php debugging wordpress
3个回答
3
投票

我在 Fedora 19 上的 Apache 2.4 中运行 WordPress 时遇到了同样的问题。 error_log() 的输出落在 /var/log/httpd/error_log 而不是 wp-content/debug.log。 httpd 进程对 /var/www/html/wp-content 目录具有写入权限 (+775),但无法创建 wp-content/debug.log 文件。

我的 wp-config.php 调试设置是:

@ini_set(‘display_errors’,0);
define('WP_DEBUG',         true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);

事实证明,真正的原因是 SELinux。我更改了 SELinux 策略并允许 httpd 使用以下命令写入 wp-content。 (请参阅 SELinux 疑难解答以获取安装的实际命令)

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/wp-content'
restorecon -v '/var/www/html/wp-content'

此后调试消息开始出现在 wp-content/debug.log 中。


1
投票

error_log() 函数写入 Web 服务器的错误日志(例如 /var/log/httpd/error_log);你想要的是 trigger_error().


0
投票

我也遇到了这个错误。我所做的是首先在 wp-content 目录下创建 debug.log 文件。我意识到错误没有记录在这个文件中。最终,我决定更改此文件的权限(右键单击 cPanel 中创建的 debug.log 文件,然后单击“更改权限”)。我更改为 777(这会启用文件的写入规则)。

希望对你有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.