As a follow up to ‘Drupal – adding debug messages to your custom module‘. I improved the code and wanted to share.
EDIT: as this code continues to evolve, I decided to store the code base / notes in a gist: https://gist.github.com/vidrowan/5506231. The latest change (5-2-13) includes a backtrace in the debug function proving the line #, function, and file name for each debug call. In addition calling the function no longer requires any text.
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.
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:
All done with cleaner code.