How to debug / log comments when developing a custom module to fire when cron is run I am about to develop a custom module that will hook into a hook that is triggered when cron runs. Since the module will be activated during a cron run, i am not sure how to go about giving myself feedback as I develop. If I was working with javascript I could use console.log(myvar) to log information about variables etc.

If I was developing a module that ran on a page I could use the devel module and use dpm() in my module code.

However since this module will run with cron, dpm() doesn't seem like the best way of doing this.

From searching around I see that watchdog('error title', 'error message'); could have been a good way of doing this in Drupal 6.

What is the Drupal 7 way of logging messages during custom module development?
The function watchdog is also available in Drupal 7

Here is an exemple of how you can use it in your case :

watchdog('MyModule', 'My message, this is my node title : %node_title', array('%node_title' =&gt; $node-&gt;title), WATCHDOG_INFO, NULL);


If you want to use a translated string you can do something like this :

watchdog('MyModule', t('My message, this is my node title : @node_title', array('@node_title' =&gt; $node-&gt;title)), array(), WATCHDOG_INFO, NULL);


If you need to print an array, you can try something like this :

watchdog('MyModule', '&lt;pre&gt;'. print_r($node, TRUE) .'&lt;/pre&gt;', array(), WATCHDOG_INFO, NULL);


You can watch the log in Reports -> Recent log messages (admin/reports/dblog) if the core module "Database logging" is activated.

Once your module is stable, you can remove the watchdog line.