apache访问日志按时间保存,每天保存一个文件
apache配置访问日志
windows:
<VirtualHost *:80> ServerName xxx ServerAlias xxx.com DocumentRoot "E:\wwwroot\web" <Directory "E:\wwwroot\web"> Options +ExecCGI +FollowSymLinks -Includes -IncludesNOEXEC -Indexes -MultiViews +SymLinksIfOwnerMatch AllowOverride All Require all granted DirectoryIndex index.php index.html </Directory> ErrorLog "logs/xxx/error.log"#错误日志 #LogFormat "%h %l %u %t \"%r\" %>s %b" Transferlog logs/acccess_log CustomLog "|bin/rotatelogs.exe logs/xxx/access_%Y%m%d.log 86400 480" common #bin/rotatelogs.exe 这个路径是相对于apache安装路径的 </VirtualHost>
linux:
<VirtualHost *:80> ServerAdmin xxx@qq.com php_admin_value open_basedir "/wwwroot/xxx:/tmp/:/var/tmp/:/proc/" DocumentRoot "/wwwroot/xxx" ServerName xxx.com ErrorLog "/home/wwwlogs/xxx-error_log" #LogFormat "%h %l %u %t \"%r\" %>s %b" #Transferlog logs/acccess_log CustomLog "| /usr/local/apache/bin/rotatelogs /home/wwwlogs/xxx/%Y_%m_%d_access_log 86400 480" combined ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/wwwroot/xxx/$1 <Directory "/wwwroot/xxx"> SetOutputFilter DEFLATE Options FollowSymLinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.html index.php </Directory> </VirtualHost>
LogLevel
指定错误级别,
LogLevel level
Apache中提供了8种level,
emerg:紧急(系统无法使用)
alert:必须立即采取措施
crit:致命情况
error:错误情况
warn:警告情况
notice:一般重要情况
info:普通信息
debug:调试信息
默认是
warn,这时debug、info级别的日志是不会记录在日志文件中的,如果是初期调试,可以设置为debug便于排错,线上环境还是用warn比较合理。
LogFormat
其格式如下:
LogFormat format|nickname [nickname]
有两种形式:
1、带一个参数,供后面的TransferLog使用,如
LogFormat "%h %l %u %t \"%r\" %>s %b"
Transferlog logs/acccess_log
2、另一种是带两个参数,为日志格式起一个别名,供后面的CustomLog指令直接使用,如
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/acccess_log common
rotatelogs的写法说明
rotatelogs logfile [ rotationtime [ offset ]] | [ filesizeM ]
最重要的是日志保存的路径一定要存在。
选项:
logfile
日志文件名,如果logfile中包含’%',则它会被视为用于的strftime(3)的格式字串;否则,它会被自动加上以秒为单位 的.nnnnnnnnnn后缀。这两种格式都表示新的日志开始使用的时间。
[ rotationtime [ offset ]] rotationtime表示日志文件回卷的以秒为单位的间隔时间
参数:[offset]
相对于UTC的时差的分钟数。默认为0,并使用UTC时间。国内一般就用480,+8时区。
参数:[ filesizeM ]
指定回卷时以兆字节为单位的后缀字母M的文件大小,而不是指定回卷时间或时差。
日志参数格式:
%…a: 远程IP地址
%…A: 本地IP地址
%…B: 已发送的字节数,不包含HTTP头
%…b: CLF格式的已发送字节数量,不包含HTTP头。例如当没有发送数据时,写入‘-’而不是0。
%…{FOOBAR}e: 环境变量FOOBAR的内容
%…f: 文件名字
%…h: 远程主机
%…H 请求的协议
%…{Foobar}i: Foobar的内容,发送给服务器的请求的标头行。
%…l: 远程登录名字(来自identd,如提供的话)
%…m 请求的方法
%…{Foobar}n: 来自另外一个模块的注解“Foobar”的内容
%…{Foobar}o: Foobar的内容,应答的标头行
%…p: 服务器响应请求时使用的端口
%…P: 响应请求的子进程ID。
%…q 查询字符串(如果存在查询字符串,则包含“?”后面的部分;否则,它是一个空字符串。)
%…r: 请求的第一行
%…s: 状态。对于进行内部重定向的请求,这是指*原来*请求 的状态。如果用%…>s,则是指后来的请求。
%…t: 以公共日志时间格式表示的时间(或称为标准英文格式)
%…{format}t: 以指定格式format表示的时间
%…T: 为响应请求而耗费的时间,以秒计
%…u: 远程用户(来自auth;如果返回状态(%s)是401则可能是伪造的)
%…U: 用户所请求的URL路径
%…v: 响应请求的服务器的ServerName
%…V: 依照UseCanonicalName设置得到的服务器名字
留言(0)