apache 日志格式和目录通常在配置文件 /etc/apache2/httpd.conf
中。
日志格式:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
分别定义了两种日志格式 combined 和 common。
声明使用了 combined 这种日志格式和写入的文件名。
CustomLog "/var/log/apache2/access_log" combined
日志样例:
192.168.1.2 - - [02/Feb/2016:17:44:13 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://localhost/x1.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36"
apache 日志格式详细说明:
%a remote_ip
%A local_ip
%B size
%b size
%D time_taken_ms
%f filename
%h remote_host
%H protocol
%l ident
%m method
%p port
%P pid
"%q" url_query
"%r" request
%s status
%>s status
%t time
%T time_taken
%u remote_user
%U url_stem
%v server_name
%V canonical_name
%I bytes_received
%O bytes_sent
"%{User-Agent}i" user_agent
"%{Referer}i" referer