Note: You are currently viewing documentation for Moodle 3.3. Up-to-date documentation for the latest stable version of Moodle is probably available here: Debugging.

Debugging: Difference between revisions

From MoodleDocs
m (removing 1.7 template)
(hiding performance info from ordinary users)
 
(40 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{Developer tools}}
{{Developer tools}}
<p class="note">'''Please refer to [[Page_notes#Developer tools|these notes]] before editing this page.'''</p>
==Using debugging messages==


Debugging messages are intended to help diagnose problems and/or help Moodle developers. If you have a problem with your Moodle site and ask for help in a Moodle.org forum, a developer may ask you to turn debug messages on, in order to locate the cause of the problem. By default Moodle does not show any error messages at all. If you are having problems (e.g. blank screens or incomplete screens) turning on debugging is usually the first thing to try.


Location: ''Administration > Development > Debugging''
==Debugging settings==


Debugging messages can be enabled by an administrator in Debugging in the Site administration.


Debugging messages are intended to help diagnose problems and/or help Moodle developers. If you have a problem with your Moodle site and ask for help in a Moodle.org forum, a developer may ask you to turn debug messages on, in order to locate the cause of the problem. By default Moodle does not show any error messages at all. If you are having problems (e.g. blank screens or incomplete screens) turning on debugging is usually the first thing to try.
===Debug messages and display debug messages===


==How to turn on debugging==
The options are:


* Access ''Administration > Development > Debugging''
* NONE: Do not show any errors or warnings (Default)
* Set ''Debug messages'' to ALL, and ''Display debug messages'' to Yes
* MINIMAL: Show only fatal errors
* NORMAL: Show warnings, errors and notices
* ALL: Show all reasonable PHP debug messages
* DEVELOPER: extra Moodle debug messages for developers


(You '''must''' do both). There is rarely any advantage in going to Developer level, unless you are a developer, in which case it is strongly recommended.
Notes:


Once you have got the error message, and copied and pasted it somewhere, you are recommended to turn debugging back off again.
# It is recommended that a record of error messages is kept, and for the admin to regularly monitor the error logs. This may be done by setting 'Debug messages' (debug) to Normal and leaving 'Display debug messages' (debugdisplay) off (unticked). Error messages are then recorded in the server logs.
# If 'Debug messages' is set to Developer on a production (public) site, it is recommended to copy and paste the debugging message obtained and then turn off Developer debugging. This is because debugging messages can give clues to a hacker as to the set-up of your site.


==Debug messages==
===Debug email sending===


Further options are provided for controlling how to handle PHP error messages. The administrator can select the types of error messages to be displayed or logged.  
Determines whether or not to enable verbose debug information during sending of email messages to SMTP server.


The options for debugging include:
==== More tools for debugging outgoing mail ====
* NONE: Do not show any errors or warnings
You can also use the config.php file to turn on more "tools" which will assist you with debugging the outgoing emails (and SMTP server configuration):
* MINIMAL: Show only fatal errors
* Redirect all outgoing emails to a specific address:
* NORMAL: Show errors, warnings and notices
<code php>
* ALL: Show all reasonable PHP debug messages. When you want to find the cause of a problem with your site, this is probably best the setting to use.
// Divert all outgoing emails to this address to test and debug emailing features
* DEVELOPER: extra Moodle debug messages for developers - If you turn this on, then PHP's error_reporting will be increased so that more warnings are printed.  This is almost essential for developers, but not very helpful for anyone else.
// $CFG->divertallemailsto = 'root@localhost.local'; // NOT FOR PRODUCTION SERVERS!
</code>


==Display debug messages==
* Turn on the CRON debugging and run CLI cron.php script.
<code php>
// Force developer level debug and add debug info to the output of cron
// $CFG->showcrondebugging = true;
</code>
And then use SSH (or putty.exe, on windows) to run:
<code php>
you@moodle-server(/var/www/html/moodle)# php admin/cli/cron.php
</code>


There is an option to choose whether to display error messages or simply record them in the server logs.
* Turn on verbose SMTP debugging and output it into system's error_log (code hack):
As [https://moodle.org/mod/forum/discuss.php?d=316222#p1289850 suggested] on Moodle's discussion forums:
Open [https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L5379 lib/moodlelib.php L5379] and change it to:
<code php>
if (!empty($CFG->debugsmtp)) {
    $mailer->SMTPDebug = 1;  // 0 - no debug ... 4 - low level full debug
    $mailer->Debugoutput = "error_log";
}
</code>
See more info about [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L314 SMTPDebug] parameters & [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L328 Debugoutput] parameters


==Debug email sending==
===Performance info===
 
Determines whether or not to enable verbose debug information during sending of email messages to SMTP server.
 
==Performance info==


The Performance info option determines whether performance info will be included in the footer of the standard theme (and some other themes). Performance info includes the time for the page to load, the amount of memory used to generate the page, cpu usage, load, and the record cache hit/miss ration.
The Performance info option determines whether performance info will be included in the footer of the standard theme (and some other themes). Performance info includes the time for the page to load, the amount of memory used to generate the page, cpu usage, load, and the record cache hit/miss ration.
Line 47: Line 67:
define('MDL_PERFTOFOOT', true);
define('MDL_PERFTOFOOT', true);
</code>
</code>
to your config.php file, then it will also count database queries. (This has to be in config.php, because Moodle starts doing DB queries before it loads the config information in the database!
to your config.php file, then it will also count database queries. (This has to be in config.php, because Moodle starts doing DB queries before it loads the config information in the database!)
 
To hide performance info from ordinary users, see the discussion [https://moodle.org/mod/forum/discuss.php?d=358032 Performance info only for admins?]
 
===Show origin of language strings===
 
Helps with [[:dev:Translation|translation]] and also with [[Language customization]]. Sometimes <code>?strings=1</code> should be added; other times <code>&strings=1</code>. See the Wikipedia article [http://en.wikipedia.org/wiki/Query_string Query string] for details.
 
===Show validator links===
Be careful, read the warning.
 
===Show page information===
To show page information printed in the page footer.


==What to do if you cannot get to the admin screens==
==What to do if you cannot get to the admin screens==
Line 55: Line 87:
===Try typing the URL directly===
===Try typing the URL directly===


The debug settings are at the URL <code><nowiki>http://.../admin/settings.php?section=debugging</nowiki></code> on your server. Sometimes that URL will work, even though the pages you need to go to to get there (for example the site front page) do not. So it is worth trying to enter that URL directly.
The debug settings are at the URL <code><nowiki>http://.../admin/settings.php?section=debugging</nowiki></code> on your server. Sometimes that URL will work, even though the pages you need to go to get there (for example the site front page) do not. So it is worth trying to enter that URL directly.


===In config.php===
===In config.php===


In moodle/config.php you can add the lines:
In [[Configuration file|config.php]] you can uncomment lines (delete the // at the start of the line) under Section 7 to enable debugging for all or just specific users:
 
<code php>
$CFG->debug = 2047;
$CFG->debugdisplay = 1;
</code>
 
Or even more debugging messages:
 
<code php>
$CFG->debug = 6143;
$CFG->debugdisplay = 1;
</code>
 
For Moodle 2.0 the possible settings are as follows:


<code php>
<code php>
//=========================================================================
// 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!
//=========================================================================
//
// Force a debugging mode regardless the settings in the site administration
// Force a debugging mode regardless the settings in the site administration
// @error_reporting(1023); // NOT FOR PRODUCTION SERVERS!
// @error_reporting(E_ALL | E_STRICT);   // NOT FOR PRODUCTION SERVERS!
@ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS!
// @ini_set('display_errors', '1');         // NOT FOR PRODUCTION SERVERS!
$CFG->debug = 38911; // DEBUG_DEVELOPER // NOT FOR PRODUCTION SERVERS!
// $CFG->debug = (E_ALL | E_STRICT);   // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!
$CFG->debugdisplay = true;   // NOT FOR PRODUCTION SERVERS!
// $CFG->debugdisplay = 1;             // NOT FOR PRODUCTION SERVERS!
 
//
// You can specify a comma separated list of user ids that that always see
// You can specify a comma separated list of user ids that that always see
// debug messages, this overrides the debug flag in $CFG->debug and $CFG->debugdisplay
// debug messages, this overrides the debug flag in $CFG->debug and $CFG->debugdisplay
// for these users only.
// for these users only.
$CFG->debugusers = '2';
// $CFG->debugusers = '2';
</code>
</code>


Remember to remove those lines again when you have finished diagnosing your problem.
Remember to comment those lines again (reinsert the // at the start of the line) when you have finished diagnosing your problem.


===In the database===
'''NOTE 1''': do not try to modify the config database table directly, it will not work because the values are cached in MUC.


Using a tool like phpMyAdmin, execute the following SQL commands:
'''NOTE 2''': if you find your config.php does not have the above settings (you have a cut down approx 30 lines config.php) look for a "config-dist.php" file that contains the full details. I would suggest transferring your details in the current config.php file you have into the full config file and renaming that one to "config.php".
 
<code sql>
UPDATE mdl_config SET value = 2047 WHERE name = 'debug';
UPDATE mdl_config SET value = 1 WHERE name = 'debugdisplay';
</code>
 
To turn it back off, use the admin screens, or the commands:
 
<code sql>
UPDATE mdl_config SET value = 0 WHERE name = 'debug';
UPDATE mdl_config SET value = 0 WHERE name = 'debugdisplay';
</code>
 
(If you use a different database prefix, you will need to adjust those commands accordingly.)


==See also==
==See also==


* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=91031 Debugging Turned on to Developer Mode on 1.8.2] forum discussion including instructions on how to turn debugging off
* Developers can also use [http://xdebug.org/ XDEBUG] (Installed as a module on the Apache server) to further dig into the code, step by step using an [http://xdebug.org/docs/remote XDEBUG client application]. Probably, as part of their favorite IDE. For example: [http://php.netbeans.org/ NetBeans], [http://www.jetbrains.com/phpstorm/ phpStorm] or...
 
[[Category:Administrator]]


[[es:Depuración]]
[[fr:Débogage]]
[[fr:Débogage]]

Latest revision as of 14:43, 7 September 2017

Using debugging messages

Debugging messages are intended to help diagnose problems and/or help Moodle developers. If you have a problem with your Moodle site and ask for help in a Moodle.org forum, a developer may ask you to turn debug messages on, in order to locate the cause of the problem. By default Moodle does not show any error messages at all. If you are having problems (e.g. blank screens or incomplete screens) turning on debugging is usually the first thing to try.

Debugging settings

Debugging messages can be enabled by an administrator in Debugging in the Site administration.

Debug messages and display debug messages

The options are:

  • NONE: Do not show any errors or warnings (Default)
  • MINIMAL: Show only fatal errors
  • NORMAL: Show warnings, errors and notices
  • ALL: Show all reasonable PHP debug messages
  • DEVELOPER: extra Moodle debug messages for developers

Notes:

  1. It is recommended that a record of error messages is kept, and for the admin to regularly monitor the error logs. This may be done by setting 'Debug messages' (debug) to Normal and leaving 'Display debug messages' (debugdisplay) off (unticked). Error messages are then recorded in the server logs.
  2. If 'Debug messages' is set to Developer on a production (public) site, it is recommended to copy and paste the debugging message obtained and then turn off Developer debugging. This is because debugging messages can give clues to a hacker as to the set-up of your site.

Debug email sending

Determines whether or not to enable verbose debug information during sending of email messages to SMTP server.

More tools for debugging outgoing mail

You can also use the config.php file to turn on more "tools" which will assist you with debugging the outgoing emails (and SMTP server configuration):

  • Redirect all outgoing emails to a specific address:

// Divert all outgoing emails to this address to test and debug emailing features // $CFG->divertallemailsto = 'root@localhost.local'; // NOT FOR PRODUCTION SERVERS!

  • Turn on the CRON debugging and run CLI cron.php script.

// Force developer level debug and add debug info to the output of cron // $CFG->showcrondebugging = true; And then use SSH (or putty.exe, on windows) to run: you@moodle-server(/var/www/html/moodle)# php admin/cli/cron.php

  • Turn on verbose SMTP debugging and output it into system's error_log (code hack):

As suggested on Moodle's discussion forums: Open lib/moodlelib.php L5379 and change it to: if (!empty($CFG->debugsmtp)) {

   $mailer->SMTPDebug = 1;  // 0 - no debug ... 4 - low level full debug
   $mailer->Debugoutput = "error_log";

} See more info about SMTPDebug parameters & Debugoutput parameters

Performance info

The Performance info option determines whether performance info will be included in the footer of the standard theme (and some other themes). Performance info includes the time for the page to load, the amount of memory used to generate the page, cpu usage, load, and the record cache hit/miss ration.

If you add define('MDL_PERF', true); define('MDL_PERFDB', true); define('MDL_PERFTOLOG', true); define('MDL_PERFTOFOOT', true); to your config.php file, then it will also count database queries. (This has to be in config.php, because Moodle starts doing DB queries before it loads the config information in the database!)

To hide performance info from ordinary users, see the discussion Performance info only for admins?

Show origin of language strings

Helps with translation and also with Language customization. Sometimes ?strings=1 should be added; other times &strings=1. See the Wikipedia article Query string for details.

Show validator links

Be careful, read the warning.

Show page information

To show page information printed in the page footer.

What to do if you cannot get to the admin screens

If the error is stopping you even getting to the admin screens to turn on debugging, then you can set the debugging setting manually.

Try typing the URL directly

The debug settings are at the URL http://.../admin/settings.php?section=debugging on your server. Sometimes that URL will work, even though the pages you need to go to get there (for example the site front page) do not. So it is worth trying to enter that URL directly.

In config.php

In config.php you can uncomment lines (delete the // at the start of the line) under Section 7 to enable debugging for all or just specific users:

//========================================================================= // 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!! //========================================================================= // // Force a debugging mode regardless the settings in the site administration // @error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS! // @ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS! // $CFG->debug = (E_ALL | E_STRICT); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS! // $CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS! // // You can specify a comma separated list of user ids that that always see // debug messages, this overrides the debug flag in $CFG->debug and $CFG->debugdisplay // for these users only. // $CFG->debugusers = '2';

Remember to comment those lines again (reinsert the // at the start of the line) when you have finished diagnosing your problem.

NOTE 1: do not try to modify the config database table directly, it will not work because the values are cached in MUC.

NOTE 2: if you find your config.php does not have the above settings (you have a cut down approx 30 lines config.php) look for a "config-dist.php" file that contains the full details. I would suggest transferring your details in the current config.php file you have into the full config file and renaming that one to "config.php".

See also