Sep*_*ram 9 php debugging wordpress
我正在尝试使用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);
Run Code Online (Sandbox Code Playgroud)
我手动创建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:~$
Run Code Online (Sandbox Code Playgroud)
在插件激活挂钩中添加了一些假定的调试输出语句,以及故意错误:
include ('i fail wp');
register_activation_hook (__FILE__, 'hello_world_activate');
function hello_world_activate()
{
error_log ('I love debug output when it works!');
}
Run Code Online (Sandbox Code Playgroud)
我期待的是关于缺少的包含文件的错误消息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=
Run Code Online (Sandbox Code Playgroud)
我怀疑该error_log()
函数不适合用于输出debug.log
,但我找不到正确的方法.哦,当然我可以硬编码文件路径并附加到它,但是,你知道......
error_log() 函数写入Web 服务器的错误日志(例如/var/log/httpd/error_log);你想要的是trigger_error()。
归档时间: |
|
查看次数: |
19534 次 |
最近记录: |