12

開発中のプラグインの WordPress で基本的なデバッグ出力を有効にしようとしています。これまでに何とか取得できましたが、 にリダイレクトできませんでしたwp-content/debug.logDouglas Neiner のガイドに大まかに従っています。これが私がしたことです:

このコード スニペットを の最後に追加しました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をローカルで実行しています):

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

プラグイン アクティベーション フック内にいくつかの想定されるデバッグ出力ステートメントと、意図的なエラーを追加しました。

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と、「I love debug output when it works!」というエラー メッセージです。メッセージ、およびページには何もありません。私が得るのは、ページメッセージにインクルードファイルがなく、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れますが、正しい方法を見つけることができませんでした。もちろん、ファイル パスをハードコーディングして追加することもできますが、ご存知のとおり...

4

2 に答える 2

2

error_log() 関数は、Web サーバーのエラー ログ (例: /var/log/httpd/error_log) に書き込みます。あなたが欲しいのはtrigger_error()です。

于 2012-12-09T22:01:13.900 に答える