2012-12-09 74 views
4

我正在嘗試使用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正確的,但我沒能找到合適的方式。噢,當然我可以硬編碼文件路徑並追加到它,但是,你知道...

+0

同樣的問題在這裏。一切正常,沒有顯示錯誤 – woens

回答

3

error_log()函數寫入Web服務器的錯誤日誌(例如/ var/log/httpd/error_log) ;你想要的是trigger_error()

+1

這並不總是正確的!我一直使用'error_log()'寫入調試日誌。我目前正在尋找一個原因,爲什麼(顯然是相同的配置)'error_log()'消息突然開始轉到apache2錯誤日誌而不是調試日誌。 –

+1

錯誤。通過添加define('WP_DEBUG_LOG',true);到wp-config這應該導致期望的行爲。 https://codex.wordpress.org/Debugging_in_WordPress#WP_DEBUG_LOG – Sandwich

2

我在Fedora 19上的Apache 2.4中遇到了同樣的問題。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中。

相關問題