Apache 2.2拆分日志

A. 使用 cronolog 为每一天创建一个新的日志

从 http://cronolog.org/download/ 能够下载 cronolog 程序,把下载到的 cronolog 程序并放到 Apache 的 bin 目录下(详细参数参见:http://cronolog.org/usage.htmlhtml

主配置文件中的使用方法 linux

ErrorLog "|bin/cronolog logs/error_%Y%m%d.log"
CustomLog "|bin/cronolog logs/access_%Y%m%d.log" combined

虚拟主机配置文件中的使用方法 web

ServerAdmin webmaster@localhost
DocumentRoot "E:/htdocs"
ServerName localhost
ErrorLog "|bin/cronolog logs/localhost/error_%Y%m%d.log"
CustomLog "|bin/cronolog logs/localhost/access_%Y%m%d.log" combined

B. 使用 rotatelogs 每隔一天记录一个日志

rotatelogs 是 Apache 2.2 中自带的管道日志程序,参数以下(参见:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/rotatelogs.htmlspa

语法
rotatelogs [ -l ] logfile [ rotationtime [ offset ]] | [ filesizeM ] .net

选项
-l
使用本地时间代替GMT时间做为时间基准。注意:在一个改变GMT偏移量(好比夏令时)的环境中使用-l会致使不可预料的结果。
logfile
它加上基准名就是日志文件名。若是logfile中包含”%”,则它会被视为用于strftime()的格式字符串;不然它会被自动加上以秒为单位的”.nnnnnnnnnn”后缀。这两种格式都表示新的日志开始使用的时间。
rotationtime
日志文件滚动的以秒为单位的间隔时间。
offset
相对于UTC的时差的分钟数。若是省略,则假定为”0″并使用UTC时间。好比,要指定UTC时差为”-5小时”的地区的当地时间,则此参数应为”-300″。
filesizeM
指定以filesizeM文件大小滚动,而不是按照时间或时差滚动。 日志

主配置文件中的使用方法 orm

ErrorLog "|bin/rotatelogs -l logs/error_%Y%m%d.log 86400"
CustomLog "|bin/rotatelogs -l logs/access_%Y%m%d.log 86400" combined

虚拟主机配置文件中的使用方法 htm

ServerAdmin webmaster@localhost
DocumentRoot "E:/htdocs"
ServerName localhost
ErrorLog "|bin/rotatelogs -l logs/localhost/error_%Y%m%d.log 86400"
CustomLog "|bin/rotatelogs -l logs/localhost/access_%Y%m%d.log 86400" combined
相关文章
相关标签/搜索