Manual:How to debug/ja

このページはMediaWikiをデバッグするための基本的な手引きです.

最初に気付くことの一つは"echo"が一般的に動作しないことです; これはデザイン全体の一部です.

PHP エラー
To see PHP errors, add this to the very top of LocalSettings.php: Or set it in :

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

In other environments:

SQL エラー
To display SQL errors in error messages instead of "(SQL query hidden)", add the following to :

プロファイルするために、profiling/debugging定数をLocalSettings.phpファイルにコピーする必要があります. 例です:

ログ
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 www-data:www-data. 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 $wgDebugDBTransactions.

カスタム ログ ファイルの作成
To create a custom log file that only holds your specific debug statements, use the  function. 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 set up log groups. To create custom log groups, add this to LocalSettings.php:

To debug to one of these groups, use a statement like this:

These logs will only contain your debug statements (not built-in MediaWiki debug information).

出力にデバッグデータを 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.


 * Manual:$wgDebugComments/ja

Working live with MediaWiki objects
eval.php 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

The MediaWiki-Vagrant portable virtual machine integrates the the interactive PHP shell.

プロファイリング
To get more detail, you need to enable profiling. Profiling tracks code execution during a page action and reports back the percentage of total code execution that was spent in any specific function. The generated profile only includes functions that have specifically been marked to be profiled. Note that you have to set  in LocalSettings; this is the file, to which your profiling data will be appended.

If you are not using profiling, but have a  file in the MediaWiki root folder, you may receive errors referring to. Deleting, or renaming, the  file will resolve this error. The  file, also in the MediaWiki root folder, can serve as a template should you enable profiling in the future.

To enable profiling, you need to modify the  (see   in the MediaWiki root folder for an example). By default the file includes a  which just dumps profiling information. To instead direct this information to a file, edit StartProfiler.php so that it looks like this:

Then you can customize profiling options in  (not  ; be sure to edit beneath the requirement of  ).

Common configuration (1.7 未満および 1.9 以降の両方):

In MediaWiki 1.7 and earlier, instead of editing, you have to set   to. This will generate basic page timing information in the file defined by.

In addition to the settings list above, these additional settings are available:

高度なプロファイリング
Once you have enabled profiling, you can trace code execution through any function that you want to investigate as a bottleneck by wrapping the function with the following code:

After you've added this information, browse to a page in the wiki. ログファイルでプロファイリング情報を見ることになります. 異なるフォーマットを表示するためにLocalSettings.phpで$wgProfileCallTreeをtrueもしくはfalseに変更してください.

データベースへのログ格納
To log profiling information to a database, set  in LocalSettings.php. Then either run update.php (since 1.21) and the profiling table will be added or manually apply the file maintenance/archives/patch-profiling.sql (the recommended way to do this is ).

プロファイル情報の閲覧
If you log your profiling information to the database, you can view the information in a webpage by browsing to. You must also set in. Then, after gathering data by browsing wiki pages, visit  to see how much time your profiled code is using and how many times it's being called.

To view profiling information as HTML comments appended to the bottom of a page, just add  to the URL. This feature is not in the standard product, you can enable it by adding this to :

関連項目

 * Resource Loader: ResourceLoader/Developing with ResourceLoader
 * All configuration variables related to debugging/logging: Manual:Configuration settings/ja
 * Useful debugging function:  (dies with an optional message and prints the callstack)
 * Manual:Errors and Symptoms/ja
 * Category:Debug variables/ja