Php WP_DEBUG_LOG设置为true时,DEBUG.LOG中没有显示调试输出,为什么?

Php WP_DEBUG_LOG设置为true时,DEBUG.LOG中没有显示调试输出,为什么?,php,debugging,wordpress,Php,Debugging,Wordpress,我正在尝试使用WordPress为我正在开发的插件启用基本调试输出。到目前为止,我设法获得了一些,但未能将其重定向到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);

我正在尝试使用WordPress为我正在开发的插件启用基本调试输出。到目前为止,我设法获得了一些,但未能将其重定向到
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);
我手动创建了
debug.log
文件,并确保
www-data
用户可以访问该文件(我在Ubuntu 12.04上本地运行WordPress):

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

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
中缺少的include文件的错误消息,以及“我喜欢调试输出,当它工作时!”消息,页面上没有任何内容。我得到的是页面消息中缺少的include文件,
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\u log()
函数不是用于输出到
debug.log
的正确函数,但我没有找到正确的方法。哦,当然我可以硬编码文件路径并附加到它,但是,你知道…

error\u log()函数会写入web服务器的错误日志(例如/var/log/httpd/error\u log);您想要的是。

我在Fedora19上的Apache2.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策略,并允许httpd使用以下命令写入wp内容。(请参阅SELinux疑难解答以获取安装的实际命令)


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

这里也有同样的问题。一切正常,没有错误显示这并不总是正确的!我一直在使用
error\u log()
写入调试日志。我目前正在寻找一个原因,解释为什么(显然是相同的配置)
error\u log()
消息突然开始进入apache2错误日志,而不是debug log.False。通过添加define('WP_DEBUG_LOG',true);要配置wp,这将导致所需的行为。
@ini_set(‘display_errors’,0);
define('WP_DEBUG',         true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/wp-content'
restorecon -v '/var/www/html/wp-content'