Drupal Object Log

Submitted by wilbur on Sat, 01/31/2015 - 1:39am

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:

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.