我正在嘗試使用WordPress爲我正在開發的插件啓用基本的調試輸出。到目前爲止,我設法取得了一些成果,但未能將其重定向到wp-content/debug.log
。我一直在大致遵循the guide by Douglas Neiner。下面是我所做的:將WP_DEBUG_LOG設置爲true時,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
用戶請確保它的訪問(我運行WordPress的本地,上Ubuntu的12.04):
[email protected]:~$ 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
[email protected]:~$ 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
[email protected]:~$ sudo su www-data -c 'echo i can write >> /usr/share/wordpress/wp-content/debug.log'
[email protected]:~$
添加插件激活鉤內的幾個所謂的調試輸出語句,以及故意錯誤:
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文件的錯誤消息,以及「當它工作時我喜歡調試輸出!」消息,並沒有在頁面上。我得到的是頁面消息中缺少的包含文件,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
正確的,但我沒能找到合適的方式。噢,當然我可以硬編碼文件路徑並追加到它,但是,你知道...
同樣的問題在這裏。一切正常,沒有顯示錯誤 – woens