4

I'm implementing a hook that is called if certain conditions are met during a cron run.

(Specifically hook_bounce_mails_blocked($mails) from the Bounce module)

The hook is triggered, but any output from dpm() functions is never shown. I do see output from var_dump() after cron finishes.

Is this normal behaviour? Is there a way to get devel output shown once cron finishes?

  • 1
    "Is there a way to get devel output shown once cron finishes?" I would like to know that as well. – David Csonka Oct 6 '14 at 17:51
  • 2
    @DavidCsonka Messages go in the session, so unless you can hijack the session the cron job happened in, the answer's got to be "no". Using other logging is the right way to go (as in loolooyyyy's answer) – Clive Oct 8 '14 at 15:58
7
+50

You should use the function dd() to log something during cron.

Here is the doc: https://api.drupal.org/api/devel/devel.module/function/dd/7

It will log the output to a file, which later you can investigate. I think you must have private file path set.

you could use something like this, But be careful about XSS!

$export = var_export($var, TRUE) // TRUE will cause var_export to return the output not print it.
$export = nl2br($export); // Convert new lines to <br> tag for display in HTML
$export = strreplace(' ', '&nbsp;'); // Again convert whitespace to HTML specific chatacter
watchdog('my_debug', $export); // That's it!

or even easier: but again be careful about CSSF and XSS

watchdog('my_debug', '<pre>' . var_export($variable) . '</pre>');

dd is the safe drupal way to go.


Update

From comments so you wont miss:

... better than dd() is ddl(), from the drupal_debug_log module that enhances > the devel module... – DrCord


Important point to developers.

If you search drupal.org modules there are many more to make development easier. After you found and used them, it would sound impossible to go without them (devel_themer to name one). An example search.

  • 1
    Even better than dd() is ddl(), from the drupal_debug_log module that enhances the devel module. ddl takes what would have been output into the file and outputs it to a log area. Basically necessary for debugging cron and ajax. Also is really useful for still getting debugging output from a script that is failing partways through. – DrCord Dec 10 '14 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.