Manual:How to debug/nl

Op deze pagina wordt een introductie voor het debuggen van de MediaWiki software gegeven.

Een van de eerste dingen die opvalt is dat "echo" in het algemeen niet werkt; dit is deel van het algemene ontwerp.



PHP fouten
Om PHP fouten te zien, voeg dit aan de 2e regel toe (net onder ) van :

Of plaats deze regels in :

Of in .htaccess:

Hierdoor worden PHP-fouten nu op de pagina getoond. Dit kan het voor kwaadwillenden gemakkelijker maken om uw server te kraken, laat dit dus alleen even zo staan tijdens uw test.

Het kan zijn dat een fatale PHP-fout optreedt in een regel die nog niet uitgevoerd is of voorkomt dat die worden getoond. Fatale PHP-fouten worden normaal gesproken gelogd in de error-log van Apache. Controleer de instelling  in   (of gebruik  ).

Er zijn meerdere configuratie-opties voor het ondersteunen van het debuggen. De volgende staan standaard op, dus uit. Het inschakelen is vanzelfsprekend het op  te zetten in uw bestand :


 * Meer details tonen (zoals een 'stack trace') op de pagina met de "Fatal error".
 * Toont een werkbalk op de pagina met o.a. profilering en logberichten.
 * Voegt het deel "logberichten" van de wgDebugToolbar aan de pagina toe als een ruwe lijst.
 * MediaWiki zal meldingen geven voor mogelijke foutcondities en voor ontraden functies.



Zet display_startup_errors aan
Enkele providers zetten  uit, dat verbergt de fouten ook als u het level   gebruikt. Het aanzetten in het programma werkt niet! Maak daarvan in plaats een wrapper bestand om uw bestand. In het geval van MediaWiki kunt u dit toevoegen bovenaan in mediawiki/index.php:

In andere omgevingen:



SQL fouten
Om SQL-queries te loggen, in plaats van alleen de queries die foutlopen: set in  ":

Voor versie 1.32 van de MediaWiki moest je de en  zetten om de details van de database-fouten te zien in de HTML-uitvoer:



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

See the XDebug documentation for more information.

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.

Inloggen
For much greater detail, you need to profile and log errors.

Setting up a debug log file
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 #Creating a custom log file to capture their output.

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

Creating a custom log file
Prior to MediaWiki 1.32, 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:

Creating custom log groups
If you're debugging several different components, it may be useful to direct certain log groups to write to a separate file. See for more information.

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

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

Structured logging
Structured logging allows you to include fields in your log records. See for more information.

Statistieken
Advanced client-side logging can be performed with, 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.

Gebruiksvoorbeeld:

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.

Send debug data to an HTML comment in the output
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

The portable virtual machine integrates the interactive PHP shell   (when using 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.

Client side debugging (JavaScript)
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.

Tools:

Many client side mediawiki scripts log error messages to the console using ResourceLoader, which 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/Architecture#Debug_mode also describes this feature.
 * ResourceLoader offers a means to ensure JavaScript is easily viewable by client-side tools.
 * Open your browser's console.
 * 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.
 * You can add  to your URL as in https://www.mediawiki.org/wiki/MediaWiki?debug=true to get more detailed information for debugging via your browser's console



Zie ook

 * ResourceLoader: ResourceLoader/Developing with ResourceLoader#Debugging
 * All configuration variables related to debugging/logging: Manual:Configuration settings#Debug/logging
 * Useful debugging tip:  (dies with the given message and prints the callstack)
 * wikitech:Debugging - debugging on Wikimedia's production cluster
 * wikitech:Debugging - debugging on Wikimedia's production cluster
 * wikitech:Debugging - debugging on Wikimedia's production cluster