Using Growl to tail a log file 24 June 2008
Mikey_p from the Portland Drupal Group pointed me towards a blog post he’d done on using Growl to watch for PHP errors. Always looking to put my fingerprints on something I decided to do the same but using PHP rather than Python.
The short version is install growlnotify then run the following from the terminal:
tail -n 0 -f ~/Sites/nm/logs/access_log | php -r 'while ($m = fgets(STDIN)) shell_exec("growlnotify -p 0 AlertTitle -m ". escapeshellarg($m));'
Obviously you’ll need to use the right filename and change AlertTitle to something more to your liking.
Update 2013-03-17: I received an email from Marcel Gleis suggesting the following improvement:
tail -n 0 -f php_error.log | php -r 'stream_set_blocking(STDIN, 0);while (true) { sleep(1);$s = ""; while (($line = fgets(STDIN)) !== false) { $s.=$line; } if ($s != "") shell_exec("echo ".escapeshellarg($s)."| growlnotify -p 0");}'
As he put it:
It aggregates multiple lines to one message. So you have less growl boxes on the screen if one page generates more than one error message.