Lighttpd – Separate log files for each vhost

I could not resist digging into my administrative and shell experience when I saw that somebody wrote a php script to dynamically split lighttpd logs. Hmm I use php for more complicated stuff.

I achieved this by putting the following into lighttpd.conf

accesslog.filename          = "|/usr/bin/splitlog.sh"


The following is the listing for splitlog.sh, shell veterans, please comment if I am overdoing this. Since my exposure is of very low.

#!/bin/bash

logDir="/var/log/lighttpd"

cat - | while read line
 do 
   dom=$(echo $line | cut -f2 -d" ")
   echo $line >> $logDir/${dom}-access.log
 done