Apache 的日志默认是直接写入一个独立的 log 文件。如果网站流量大,日志文件很快就会变得很庞大;而 AWStats 等日志分析软件,要求日志文件以天的格式保存。Cronolog 正好可以解决这个问题:它可以对 Apache 的日志按需要进行截断处理(cronolog 也是Apache推荐使用的日志工具之一),是使用 AWStats 进行日志分析的基础。这是 Cronolog 官方网站上的介绍: Cronolog is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time. When the expanded filename changes, the current file is closed and a new one opened. cronolog is intended to be used in conjunction with a Web server, such as Apache, to split the access log into daily or monthly logs. 简单地说明一下 cronolog 在 Windows + Apache 下的安装: 首先到 Cronolog 的网站:http://www.cronolog.org/ 下载。注意应该下载 Win 32 version (ZIP file) 的版本。目前最新的 win 32 version 是 1.6.1。 将 zip 文件下载之后,将 cronolog.exe 解压并复制到 Apache 的 bin 目录 在 apache 的配置文件 httpd.conf 中, 修改以下代码:
CustomLog "|bin/cronolog.exe D:/LogFiles/access_%Y%m%d.log" combined ErrorLog "|bin/cronolog.exe D:/LogFiles/error_%Y%m%d.log"也可以在虚拟主机配置中使用,例如:
<VirtualHost *:80> ServerName www.piaoyun.cc CustomLog "|bin/cronolog.exe D:/LogFiles/piaoyun.cc/access_%Y%m%d.log" combined ErrorLog "|bin/cronolog.exe D:/LogFiles/piaoyun.cc/error_%Y%m%d.log" </VirtualHost>重新启动 Apache. 其中 D:/LogFiles 表示你的log存放的路径;|bin/cronolog.exe为cronolog所在的路径,可以通过 which cronolog 的命令来查看;%Y_%m_%d表示按照年月日来分割,这样一个月就会生成一个日志文件,如果要按照每天生成一个日志文件,是%Y%m%d 然后重启一下apache,就会发现apache日志开始按照日期生成,而原来的apache日志文件就不会再记录新的访问数据了。 其他设置说明,请见下载包中的 README 文件。 Linux下的配置文件说明:
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache/logs/%Y_%m_%d.access.log" combined这里是按照每天来生成日志的 其中,/home/apache/logs 表示你的log存放的路径;/usr/local/sbin/cronolog为cronolog所在的路径,可以通过 which cronolog 的命令来查看;%Y_%m_%d表示按照年月日来分割,这样一个月就会生成一个日志文件,如果要按照每天生成一个日志文件,是%Y%m%d 然后重启一下apache,就会发现apache日志开始按照日期生成,而原来的apache日志文件就不会再记录新的访问数据了。