University of Oregon

Drupal – adding debug messages to your custom module – Improved

As a follow up to ‘Drupal – adding debug messages to your custom module‘. I improved the code and wanted to share.
Now you can drop in a few functions and add one line to your hook_admin_settings function to get debugging functionality.
If you want to start with a baseline of functionality you can also update each of your functions to declare themselves in the debug messages. Which is handy for tracking down issues.

In the end you get the same addition to your GUI with control over how and when debug messages are used.
Screen Shot of the new checkboxes
You also get the same reporting output, to the screen, watchdog, or both:
Here’s a quick look at my watchdog log gui with both types of error reporting enabled:
Screen Shot of watchdog screen

All done with cleaner code.
(more…)

Drupal – adding debug messages to your custom module

Note: There is a follow up post here: Drupal – adding debug messages to your custom module – Improved


I work with a few custom modules and lately I’ve been migrating one from PHP 5.2 to 5.3 & Webform 2 to 3.

It’s been a challenge to sort out where some of the the errors are being generated from so I added a grip of debugging statements. In fact, I used a regex replace to log the name of each function that’s run in hopes that I could track down errors in chronological order.

That worked OK but I though I may want to turn it off or switch from drupal_set_message() to watchdog() calls when it’s ready to go to production. So I wrapped each log item in an if statement and tested for two new module variables:

  • Enable debugging message feedback
  • Enable watchdog debugging feedback

So now I have some GUI control over how and when debug messages are used.
Screen Shot of the new checkboxes
(more…)