Drupal debugging tip – use the logging console
I recently ran across a feature of Drupal’s devel.module that might not be all that well known, namely that it has a facility for debug logging as well as the <code>dpm()</code> I’ve advocated to my fellow developers for a long time.
That is the <code>dd()</code>-command which instead
of logging to screen simply outputs a print_r()
to a file called
drupal-debug.txt
in your temporary files folder (where that is depends
on your site configuration, but /tmp
might be a good place to look).
That alleviates the many problems of simply logging to screen (doesn’t
work with AJAX, redirects, causes browser slowness for large datasets,
lots of junk in your HTML source, etc.). You can then simply run
tail -f /tmp/drupal-debug.txt
to see what’s going on – and for those
of you that use Mac OS X, I have an additional trick.
OS X ships with a fairly good log viewer, namely Console.app – by default, it’s installed in Applications/Utilities. That can be used to view all the logs in standard locations, but with a little trick, it can be used to view this log file also.
Console has a section for ~/Library/Log
, ie. the Log folder in the
Library folder in your home folder. You can then set up a symbolic link
to the log file there. I have a subfolder in ~/Library/Log
called
apache2, and I also have my Apache log files symlinked in there as well.
Anyways, the procedure to set it up looks like this:
cd ~/Library/Logs/
ln -s /tmp/drupal_debug.txt