简体   繁体   English

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

[英]With WP_DEBUG_LOG set to true, no debug output shows in debug.log, why?

I'm trying to enable basic debug output with WordPress for a plugin I'm developing. 我正在尝试使用WordPress为我正在开发的插件启用基本调试输出。 I managed to get some so far, but failed to redirect it to wp-content/debug.log . 到目前为止,我设法得到了一些,但未能将其重定向到wp-content/debug.log I've been roughly following the guide by Douglas Neiner . 我一直在粗略地遵循Douglas Neiner的指南 Here's what I did: 这是我做的:

I added this snippet of code to the end of wp-config.php : 我在wp-config.php的末尾添加了这段代码:

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

I manually created debug.log file and made sure it's accessible by www-data user (I'm running WordPress locally, on Ubuntu 12.04): 我手动创建了debug.log文件并确保它可以被www-data用户访问(我在本地运行WordPress,在Ubuntu 12.04上):

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:~$

Added a few supposed debug output statement inside the plugin activation hook, as well as the intentional error: 在插件激活挂钩中添加了一些假定的调试输出语句,以及故意错误:

include ('i fail wp');

register_activation_hook (__FILE__, 'hello_world_activate');

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

What I expect is an error message about the missing include file in debug.log along with the "I love debug output when it works!" 我期望的是一个关于debug.log缺少的包含文件的错误消息以及“我喜欢调试输出时它的工作原理!” message, and nothing on the page. 消息,页面上没有任何内容。 What I get is the missing include file on the page message and nothing in debug.log . 我得到的是页面消息上缺少的包含文件,而debug.log没有。 The debug output message is not fully lost, however. 但是,调试输出消息并未完全丢失。 I found it in the /var/log/apache2/error.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=

I suspect that the error_log() function is not the right one to use to output to debug.log , but I failed to find the right way. 我怀疑error_log()函数不是用于输出到debug.log的正确函数,但我找不到正确的方法。 Oh, of course I could just hardcode the file path and append to it, but, you know... 哦,当然我可以硬编码文件路径并附加到它,但是,你知道......

the error_log() function writes to the web server's error log (eg /var/log/httpd/error_log); error_log()函数写入Web服务器的错误日志(例如/ var / log / httpd / error_log); what you want is trigger_error() . 你想要的是trigger_error()

I encountered the same problem with WordPress running in Apache 2.4 on Fedora 19. Output of error_log() was landing in /var/log/httpd/error_log instead of wp-content/debug.log. 我在Fedora 19上的Apache 2.4中运行的WordPress遇到了同样的问题.inror_log()的输出登陆/ var / log / httpd / error_log而不是wp-content / debug.log。 Httpd process had write permission (+775) to /var/www/html/wp-content directory, but it was unable to create the wp-content/debug.log file. Httpd进程对/ var / www / html / wp-content目录具有写权限(+775),但无法创建wp-content / debug.log文件。

My wp-config.php debug setting was: 我的wp-config.php调试设置是:

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

As it turned out, the real cause was SELinux. 事实证明,真正的原因是SELinux。 I made SELinux policy change and allowed httpd to write to wp-content with following commands. 我进行了SELinux策略更改,并允许httpd使用以下命令写入wp-content。 (Refer SELinux Troubleshooter to get the actual command for your installation) (请参阅SELinux Troubleshooter以获取安装的实际命令)

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

After this debug messages start appearing in wp-content/debug.log. 此调试消息开始出现在wp-content / debug.log中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM