Does anybody know of the proper way to debug objects from within hook_cron? I'm trying to set up a task that periodically deletes backups from my private folder, but I can't properly debug arrays that I define in my module. I've tried both the object log and devel debug log modules, but neither of them are properly working for me at the moment, so I feel completely stuck on how to access the information I need.

I've tried running kint() directly, but I'm assuming that doesn't work because it's not running on a page load but in the middle of the cron task.

EDIT: Ended up solving this particular piece of the issue, but am having errors doing some of the deletion as addressed in another issue.

4 Answers 4


You might want to try a module like Ultimate Cron that allows you to run individual cron jobs, outside of cron.php. This will allow you to use kint() and see the output.

  • Great suggestion! Except that the individual cron job running functionality seems to be broken right now, at least on my end. I wonder if I've got another issue going on, here, that's affecting everything I'm trying...
    – Mrweiner
    Commented Jan 31, 2017 at 22:54
  • Actually that may have been an alpha vs dev issue, because I switched over to the most recent dev version and the individual runs are working. Still no sign of my kint messages on screen, though. : /
    – Mrweiner
    Commented Jan 31, 2017 at 23:35

I ended up using Ultimate Cron to run my specific cron task on demand, but used a method other than kint() to print my info. I ended up setting my info to a variable $folders and using the following to print the information in a text file: file_put_contents("$private_path/folders.txt", print_r($folders, true))


It is possible to log an array in dblog :

Drupal::logger('my_cron_task')->notice('<pre><code>' . print_r($myArray, TRUE) . '</code></pre>');

Other way is to debug with cli, so in your hook_cron() you print your array ...


... then you launch your cron task from your cli with drush :

drush cron

echo are displayed with drush on hook_cron.

A quick but not complete solution could be to echo flat array using this way. It could do the trick depending of your need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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