Drupal Object Log

Over the past few months I have been writing array object to watchdog as messages.  This is pretty handly for seeing LOTS of variable arrays in some sort of order.  Here's a snippet from Dropbucket where I got the idea:

watchdog("my_module", '<pre>' . print_r( $my_array_or_object, true) . '</pre>');

This approach might be OK on your local dev environment, but you do NOT want to do this on your live site!  All those messages become translatable strings, and get piled up in the translation table.  That becomes a big mess quick.  

So what to do with all those arrays?  

Object Log to the Rescue!

There are no new ideas, just new tools.  And this one provides us an extension of the Devel module that provides us a space to dump what we want in the object log.  The syntax is simple, just plug it in and go!

<?php
  object_log($label, $data);
?>

You can get as crazy as you want with loops and labels, making all the object logs you need!  You can even diff the content of two objects.  

Just what we need!

 

Resources

Naughty watchdog on DropBucket - http://dropbucket.org/node/72

Object Log module on Drupal.org - https://www.drupal.org/project/object_log