April 5th, 2010

Quick Tip: Use Terminal to Read Live Traces

On a recent PHP project, I was having trouble with the somewhat ridiculous PHP error handling and Alec, a developer here, pointed me to the terminal “tail” command.  This command keeps a persistent connection open to a file and reads the contents into a terminal window.  Using it I was able to tail the php_error_log file, which gave me a full readout of errors regardless of 17 different ways to set PHP error levels. This technique can also be used for debugging Flash content.

All Flash errors are actually also written to a log file.  For Mac users it can be found at: /Users/username/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt and for Windows users at: C:\Documents and Settings\username\Application Data\Macromedia\Flash Player\Logs

So why is this interesting?  It’s not just when you’re debugging that traces are written to this file.  If you visit any website that contains traces, warning, or errors, you’ll see this file change.  Effectively, we can monitor traces from live pages.  Pretty cool!  If you’ve ever used Alessandro Crugnola’s FlashTracer extension for Firefox (now depreciated?) it’s a very similar functionality.  This might be useful in debugging from live servers, though you’d be better off considering a solution like Arthropod, which we at the Ship are fond of.

The command looks something like this:

tail -f /Users/username/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt

Note that I’m using the ‘-f’ flag (follow) which keeps the connection open.  Without that, it would just read back the last 50 lines in the file and then stop.