Archive for the ‘Programing’ Category

Debugging Moodle

Friday, May 30th, 2008

bug1.jpgOne of the first things i noticed when i started playing around with Moodle’s code was that PHP errors would not show up when you made a mistake in your code and you would be greeted with a blank white page or just part of the page missing when you try to load a page with an error on it. This is due to error catching that Moodle is doing witch is a good thing when you have production level code and users using your site but for development it makes debugging code a pain.

To see PHP errors and warnings simple go to Server -> Debugging in the administration options and you can select the level of PHP error reporting from only fatal errors, warnings and notices, all PHP debugging messages and a developer level that will give you even more then PHP error reporting and add additional Moodle related debugging messages. On this page you can also set if you want errors to go to a log file, witch is use full if you still have normal users on your site and do not want to break the layout or cover the page in debugging messages, or to put the errors in the html. There is also a nice option built in to send errors to an e-mail address when they happen so during production you will be notified of new possible bugs and errors live (i had to manually add this kind of feature to and software, so it is nice to see it built in to Moodle). Lastly there is an option to add performance related debugging information to the footer, witch is good for testing if your effected the performance of the software.

You can further tweak the performance debugging information by editing the config-dist.php file:

From the config-dist.php comments

// Performance profiling
// If you set Debug to "Yes" in the Configuration->Variables page some
// performance profiling data will show up on your footer (in default theme).
// With these settings you get more granular control over the capture
// and printout of the data
// Capture performance profiling data
// define('MDL_PERF' , true);
// Capture additional data from DB
// define('MDL_PERFDB' , true);
// Print to log (for passive profiling of production servers)
// define('MDL_PERFTOLOG' , true);
// Print to footer (works with the default theme)
// define('MDL_PERFTOFOOT', true);

If for some reason you can not get to Server -> Debugging you can still get debugging information by either editing the database or adding a few lines to config.php.

In config.php add:


or in the database:

UPDATE `mdl_config` SET `value` = '2047' WHERE `name` ='debug';

This post is based on information i found in the Moodle documentation and wiki witch can be found here.