Jak hezky pouzivat logy apache

1. definujeme si v apache2.conf specielni format logu:
LogFormat “%v %h %l %u %t \”%r\“ %>s %b \”%{Referer}i\“ \”%{User-Agent}i\“” dalibor_vhost

2. u virtualniho hosta nedefinujeme zadny log

3. definujeme globalne v /etc/apache2/conf/custom.conf
CustomLog “|/usr/bin/cronolog /var/log/apache2/access-%Y%m%d.log” dalibor_vhost

4. je treba mit nainstalovan cronolog ;-)

5. nainstalovat split-logfile, v Debianu je v baliku apache2-utils

6. ted staci napsat

cd /here/go/virtual.hosts.logs
cat /var/log/apache2/access-20090418.log | split-logfile

7. A mame to!

Nejaky skript pro webalizer

#!/bin/sh

day=$(date +%Y%m%d -d "-1 day")
m=$(date +%Y%m -d "-1 day")
#day="20081003";
#m="200810";

rm -rf /var/tmp/webalizer/*
cat /var/log/apache2/access-${day}.log | /usr/sbin/logs/split-logfile
#exit 0;
for f in /var/tmp/webalizer/*.log
do
  w=$(echo ${f} | sed -e 's/\/var\/tmp\/webalizer\///' -e 's/\.log//')
  echo "Procesing ${w} (${f})... " 
  if [ -d /var/www/${w} ]
  then
    cat ${f} >> /var/www/${w}/logs/${m}.log
    ln -s -f /var/www/${w}/logs/${m}.log /var/www/${w}/logs/apache.log

    cat /usr/sbin/logs/.template | sed -e "s/_SITE_/${w}/" > /var/tmp/webalizer-$$.conf
    /usr/bin/webalizer -c /var/tmp/webalizer-$$.conf
    rm -f /var/tmp/webalizer-$$.conf

    chown -R www-data:www-data /var/www/${w}/logs /var/www/${w}/stats
  else
    echo "Site ${w} currently does not exist. Skipping! "
  fi
  echo "done."
done

rm -rf /var/tmp/webalizer/*

exit 0
 
linux/apache/split-logfile.txt · Last modified: 2009/08/12 18:13 by admin