Manual:How to debug/ja

このページでは、MediaWiki をデバッグするソフトウェアの基礎を紹介します.

最初に気付くことの 1 つは、"echo" が全般的に動作しないということでしょう. この挙動は全般的な設計の一部です.

PHP のエラー
PHP のエラーを閲覧するには、 の2行目の先頭 ( の直下) に以下を追加します:

または 内で設定します:

あるいは .htaccess 内で設定します:

This will cause PHP errors to be shown on-page. This might make it easier for attackers to find a way into your server, so disable it again when you have found the problem.

Note that fatal PHP errors may happen before the lines above are ever executed, or may prevent them from being shown. Fatal PHP errors are usually logged to Apache's error log – check the  setting in   (or use  ).

There are several configuration options to aid debugging. The following are all  by default. Enable them by setting them to  in your :
 * Enable more details (like a stack trace) to be shown on the "Fatal error" page.
 * Shows a toolbar on the page with profiling, log messages and more.
 * Adds the "log messages" part of wgDebugToolbar as a raw list to the page.
 * MediaWiki will throw notices for some possible error conditions and for deprecated functions.

display_startup_errorsをonにする
Some providers turn  off, which hides the errors even if you raise the   level. Turning it on within the program is too late! Instead you'll have to create a wrapper file around your file. In the case of MediaWiki you can just add this on top of mediawiki/index.php:

その他の環境では:

SQLのエラー
To log all SQL queries, rather than just the one that raised the exception, set in  :

Prior to MediaWiki 1.32, you needed to set and  to see details of database exceptions in the HTML output:

デバッガー
For the most common setup (using MediaWiki-Vagrant and PhpStorm) see.

Zend
If you are using the Zend PHP interpreter, you can debug your code with XDebug. MediaWiki-Vagrant has built in settings for this. If you're not using MediaWiki-Vagrant, but your setup is similar, you can reuse those values. In some cases (e.g. due to a firewall), you may have to use the IDE on the same machine as the web server. In this case, you can simply set:

If you use this configuration, you may run into an issue if HHVM is also listening on the machine. Both XDebug and HHVM use port 9000 by default. However, you can change this for XDebug (and many clients). For the XDebug side, use:

Remember if you change it for XDebug, you must also change it for your IDE.

詳細情報については XDebug の説明文書を参照してください.

To debug a command-line script (e.g. PHPUnit, or a maintenance script) on MediaWiki-Vagrant, use:

Adjust the script, parameters, and remote host (it should be the IP of the computer where your IP is, 10.0.2.2 should work for MediaWiki-Vagrant) as needed.

HHVM
If you are using the HHVM PHP runtime, you can debug your code with the built in CLI debugger and debug server. (XDebug also usually works, but is less reliable than on Zend.) このデバッガーは GDB に何となく似ています.

In order for the cli debugger to attach to web requests the hhvm.debug.enable_debugger parameter needs to be enabled. This is enabled by default on the mediawiki-vagrant development environment.

With this enabled the process is:

$ hhvm -m debug --debug-host localhost --debug-port 8089 localhost> machine list machine list 1    vagrant's default sandbox at /vagrant/www/ 2    __builtin's default sandbox at / localhost> machine attach 2 machine attach 2 Attaching to __builtin's default sandbox at / and pre-loading, please wait... localhost> break MediaWiki::run break MediaWiki::run Breakpoint 1 set upon entering MediaWiki::run localhost> continue continue

machine attach 2 が必要です. It may not always be machine 2, but it will always be the one identified as "__builtin's default sandbox at /". This is only true on configurations that pass a  over fastcgi to hhvm (such as  and wmf production), alternate configurations may vary.

At this point the next web request that enters MediaWiki::run (all of them) will break and put you on a command prompt:

Breakpoint 1 reached at MediaWiki::run on line 450 of /vagrant/mediawiki/includes/MediaWiki.php 449           try { 450*                  $this->checkMaxLag; 451                   try { localhost>

The HHVM CLI debugger has an excellent help system, for example try help break for details on the syntax of choosing break points.

ログ作成
For much greater detail, you need to profile and log errors.

デバッグ ログ ファイルのセットアップ
To save errors and debugging information to a log, add  to the   file. Change the value to a text file where you want to save the debug trace output.

The MediaWiki software must have permissions from your operating system to create and write to this file, for example in a default Ubuntu install it runs as user & group :. Here's a sample setting:

This file will contain much debug information from MediaWiki core and extensions. Some subsystems write to custom logs, see to capture their output.

Database transaction lifecycle debugging can be enabled for some databases with.

カスタムログファイルの作成
To create a custom log file that only holds your specific debug statements, use the  function (use of wfErrorLog was deprecated in MediaWiki 1.25). This function takes two arguments, the text string to log and the path to the log file:

カスタムロググループの作成
If you're debugging several different components, it may be useful to direct certain log groups to write to a separate file. 詳細情報は を参照してください.

To set up custom log groups, use the following to LocalSettings.php:

To log to one of these groups, call  like this:

構成した記録
構成した記録によりログにフィールドを追加できます. 詳細情報は を参照してください.

統計
Advanced client-side logging can be performed with Extension:EventLogging, which requires a complex setup and careful inspection of privacy issues.

Simple counting of certain kind of events is possible (since MediaWiki 1.25) using StatsD. StatsD offers meters, gauges, counters, and timing metrics.

使用例:

The metrics can be sent to a StatsD server, which may be specified via the  configuration variable. (If not set, the metrics are discarded.) You can work with StatsD locally (without needing a Graphite server) by starting a StatsD server and configuring it with the "backends/console" backend, which will output metrics to the console.

As of MediaWiki 1.25,  is a shortcut for the   method on the main   instance.

出力結果のHTMLコメントにデバッグデータを含める
This may occasionally be useful when supporting a non-technical end-user. It's more secure than exposing the debug log file to the web, since the output only contains private data for the current user. But it's not ideal for development use since data is lost on fatal errors and redirects. Use on production sites is not recommended. Debug comments reveal information in page views which could potentially expose security risks.



Working live with MediaWiki objects
is an interactive script to evaluate and interact with MediaWiki objects and functions in a fully initialized environment.

$ php maintenance/eval.php > print wfMessage("Recentchanges")->plain; Recent changes

携帯用の VM は対話型 PHP シェル   (既定の HHVM 使用時) もしくは   (Zend　使用時) を統合する.

Callable updates
Code embedded in the  function, such as   in , is not executed during the web request, so no error message will be displayed if it fails. For debugging, it may be helpful to temporarily remove the code from within the function so that it is executed live.

クライアント側のデバッグ
Wikipedia offers a rich set of tools for debugging client side JavaScript. In addition to the MediaWiki tools, other techniques are available to assist with diagnosing client interactions.

ツール:


 * ResourceLoader offers a means to ensure JavaScript is easily viewable by client-side tools.
 * ResourceLoader also provides a safety oriented way to log to the client console. Beyond the native JavaScript logging function, it provides a check to ensure that a console is available and that logging does not produce its own error. ResourceLoader/Features also describes this feature.
 * Browser tools may provide native functionality to debug client side script.
 * Network tracers, like Wireshark can provide insight into the script that is being provided by a page.

関連項目

 * /Login problems
 * Manual:プロファイル
 * ResourceLoader: ResourceLoader/Developing with ResourceLoader
 * デバッグ・ログ取得に関わるすべての構成変数: Manual:構成設定#デバッグ・ログ取得
 * デバッグに使えるヒント:  (特定のメッセージにより解除しコールスタックを出力)
 * Manual:エラーと症状
 * wikitech:Debugging - debugging on Wikimedia's production cluster
 * wikitech:Debugging - debugging on Wikimedia's production cluster