Debugging Moodle

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.

6 Responses to “Debugging Moodle”

  1. The Third Bit » Blog Archive » Three Weeks In Says:

    […] instructors would actually like to visualize, and is now working on a final design and figuring out how to debug […]

  2. JDS Says:

    It’s “which” not witch.

    A witch is a magic hag in a pointed hat.



  3. Summer Says:

    Dan - I am teaching a Moodle course at Emporia State University about Moodle and I would LOVE to use your Moodle Bug character. Is it yours? May I borrow it?

    Thanks so much,

  4. Rex Says:

    Note, in Moodle 2.0 the debugging menu has changed to Settings > Site Administration > Development > Debugging.

    I found this blog post in a google search wondering why errors weren’t showing up on my moodle setup, so I thought this update might help others as well.

  5. richard Says:

    Hi Dan

    I am trying to set the debug option to developer and show in a html window. the 1st two boxes are ticked in the debug window…. however when i am running a scorm course, it is bookmarking and tracking but the debug window is not opening…. do you have any idea why? what i can do as i have set the debug options to on and the popup blocker is off in internet explorer.

    help would be much apprecaited.



  6. Roger Kidd Says:

    I am trying to set the debug option.really it’s nice post.
    Thanks for sharing this post.

Leave a Reply