Manual:How to debug/es

Aquí te damos una introducción básica sobre depurar el software MediaWiki

Una de las primeras cosas que encontrarás es que las instrucciones echo por lo general no funcionarán. Esto es parte del diseño general.

Errores PHP
Para mostrar errores PHP, añade esto al final de :

O configúralo en :

O configura en .htaccess:

Esto causará que los errores de PHP se muestren directamente en la página. Esto podría facilitar a un atacante el encontrar alguna manera de comprometer tu servidor, así que desactívalo en cuanto hayas encontrado el problema.

Ten en cuenta que los errores fatales pueden suceder antes de que las líneas de código anteriores se hayan podido ejecutar, o prevengan que estos se muestren. Los errores fatales de PHP normalmente quedan registrados en el registro de errores de Apache. Revisa la configuración  en   (o consúltalo en  ).

Existen algunas variables de configuración que ayudan a depurar errores. Las siguientes tienen valor  de forma predeterminada. Actívalas estableciendo su valor a  en :
 * Activa más detalles (como la pila de llamadas) que se mostrarán en la página de "Error fatal".
 * Muestra una barra de herramientas en la página con datos de perfilado, registro de mensajes y más.
 * Agrega la parte de "log messages" de wgDebugToolbar como una lista en crudo en la página.
 * MediaWiki lanzará avisos sobre algunas posibles condiciones de error y de funciones obsoletas.

Activar display_startup_errors
Algunos proveedores establecen  en off, causando que los errores queden ocultos incluso si aumentas el nivel de. Activar esta configuración durante la ejecución del programa es demasiado tarde. En su lugar, debes crear un contenedor sobre tu archivo. En el caso de MediaWiki, bastará con añadir lo siguiente al inicio de mediawiki/index.php:

En otros entornos:

Errores SQL
Para mostrar errores de SQL en mensajes de error en lugar de "(SQL query hidden)", agrega lo siguiente a :

También puedes activar el seguimiento de la pila de llamadas en caso de error SQL estableciendo :

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.

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.

HHVM
If you are using the HHVM PHP runtime, you can debug your code with the built in CLI debugger and debug server. This debugger is vaguely similar to 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

The machine attach 2 is required. 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.

Registros
Para un mayor detalle, necesitas perfilar y registrar los errores.

The instructions below are only valid for the default configuration. If you change, for example enable the   role on a  box, these settings will probably be ignored.

Configurar un registro de depuración
Para guardar errores e información de depuración en un archivo, agrega  al archivo. Establece su valor a la ruta de un archivo de texto donde quieras guardar la salida del registro de errores.

El software de MediaWiki debe tener el permiso del sistema operativo para crear y escribir a este fichero. Por ejemplo, en una instalación estándar de Ubuntu, se ejecutará con el usuario y grupo :. Este sería un ejemplo de configuración:

Este archivo contendrá gran cantidad de información de depuración del núcleo de MediaWiki y sus extensiones. Algunos subsistemas escriben en registros especializados, consulta para capturar su salida.

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

Crear un registro de depuración personalizado
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:

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.

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

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

Registro estructurado
Structured logging allows you to include fields in your log records. Véase para más información.

Estadísticas
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.

Ejemplo de uso:

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 the default HHVM) or   (when using Zend).

Callable updates
Code embedded in the DeferredUpdates::addCallableUpdate function, such as $rc->save in RecentChange.php, 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
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.

Herramientas:


 * 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.

Véase también

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