July 10, 2012 - Comments Off on Drush de Jour: Debugging Drupal modules

Drush de Jour: Debugging Drupal modules

Ever want to see what's happening behind the scenes on your Drupal site? With Drush you can do just that. Whether you are building, debugging or unintentionally breaking a Drupal site, the system logs are an invaluable way to see what is going on. Strange behavior of a module? Rules not working as expected? the logs can tell you a great deal. You can access the logs by browsing to Reports>Recent log messages (/admin/reports/dblog) and view and filter the messages. You can however get a realtime view of everything being written to the log with Drush.

% drush watchdog-show --tail

This command will let you all the messages as they come in. Keep that terminal window open and you can see users log in, rules being fired, module/php errors, and your own custom debug() and watchdog() messages. You will even see PHP warnings being thrown that may not break your site but indicate coding errors that won't be obvious by just using a browser to test.

Logic loops in modules can get complicated and sometimes you can't print out a standard debugging message to the browser with print or dpm depending on where in the rendering process your code occurs. You can however put in watchdog() statements inside your loops to let you see where your code is taking you. You could add logging to an existing module if you want to learn how it works and how you can hook into it. Just be sure to make backups if you're not working in a development environment.

All your log are belong to Drush!

The Drush de Jour brings you the latest and possibly greatest bits of drush wisdom we use for developing and maintaining our Drupal sites.

 

Published by: chazcheadle in The Programming Mechanism
Tags: ,

Comments are closed.