apache 学习笔记 系列之 日志 apache log 学习笔记

记录apache 配置有关的信息

参考资料:http://httpd.apache.org/docs/2.2

[log]

参考资料:http://httpd.apache.org/docs/2.2/en/logs.html

TransferLog 

ex)

TransferLog /var/log/httpd/error_log

ErrorLog

ErrorLog | LogLevel

ex)ErrorLog /var/log/httpd/error_log

ex)ErrorLog "|/usr/local/bin/httpd_errors"

ex)ErrorLog syslog:user

LogLevel:

LevelDescriptionExampleemergEmergencies – system is unusable."Child cannot open lock file. Exiting"alertAction must be taken immediately."getpwuid: couldn’t determine user name from uid"critCritical Conditions."socket: Failed to get a socket, exiting child"errorError conditions."Premature end of script headers"warnWarning conditions."child process 1234 did not exit, sending another SIGHUP"noticeNormal but significant condition."httpd: caught SIGBUS, attempting to dump core in …"infoInformational."Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)…"debugDebug-level messages"Opening config file …"

AccessLog

ex)

LogFormat "%h %l %u %t "%r" %>s %b" common

CustomLog logs/access_log common

ex)

LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"" combined

CustomLog log/access_log combined

ex)

LogFormat "%h %l %u %t "%r" %>s %b" common
CustomLog logs/access_log common
CustomLog logs/referer_log "%{Referer}i -> %U"
CustomLog logs/agent_log "%{User-agent}i"

Conditional Logs

ex)

# Mark requests from the loop-back interface
SetEnvIf Remote_Addr "127.0.0.1" dontlog
# Mark requests for the robots.txt file
SetEnvIf Request_URI "^/robots.txt$" dontlog
# Log what remains
CustomLog logs/access_log common env=!dontlog

LogFormat

Log Rotation 

ex)

mv access_log access_log.old
mv error_log error_log.old
apachectl graceful
sleep 600
gzip access_log.old error_log.old

##stupid way,see below.

Piped Logs

ex)

CustomLog "|/usr/local/apache/bin/rotatelogs /var/log/access_log 86400" common

# Invoke "rotatelogs" without using a shell
CustomLog "||/usr/local/apache/bin/rotatelogs /var/log/access_log 86400" common

 Virtual Hosts

ex)

LogFormat "%v %l %u %t "%r" %>s %b" comonvhost
CustomLog logs/access_log comonvhost

#The %v is used to log the name of the virtual host that is serving the request.

Pid File

ex)

PidFile /var/run/apache.pid

#change the pid file location

Script Log

In order to aid in debugging, the ScriptLog directive allows you to record the input to and output from CGI scripts. This should only be used in testing – not for live servers. More information is available in the mod_cgi documentation.

Rewrite Log

When using the powerful and complex features of mod_rewrite, it is almost always necessary to use the RewriteLog to help in debugging. This log file produces a detailed analysis of how the rewriting engine transforms requests. The level of detail is controlled by the RewriteLogLevel directive.

 CustomLog Format

Format String   Description

%%                The percent sign

%a                Remote IP-address

%A                Local IP-address

%B                Size of response in bytes, excluding HTTP headers.

%b                Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a ‘-’ rather than a 0 when no bytes are sent.

%{Foobar}C        The contents of cookie Foobar in the request sent to the server. Only version 0 cookies are fully supported.

%D                The time taken to serve the request, in microseconds.

%{FOOBAR}e        The contents of the environment variable FOOBAR

%f                Filename

%h                Remote host

%H                The request protocol

%{Foobar}i        The contents of Foobar: header line(s) in the request sent to the server. Changes made by other modules (e.g. mod_headers) affect this.

%k                Number of keepalive requests handled on this connection. Interesting if KeepAlive is being used, so that, for example, a ’1′ means the first keepalive request after the initial one, ’2′ the second, etc…; otherwise this is always 0 (indicating the initial request). Available in versions 2.2.11 and later.

%l                Remote logname (from identd, if supplied). This will return a dash unless mod_ident is present and IdentityCheck is set On.

%m                The request method

%{Foobar}n        The contents of note Foobar from another module.

%{Foobar}o        The contents of Foobar: header line(s) in the reply.

%p                The canonical port of the server serving the request

%{format}p        The canonical port of the server serving the request or the server’s actual port or the client’s actual port. Valid formats are canonical, local, or remote.

%P                The process ID of the child that serviced the request.

%{format}P        The process ID or thread id of the child that serviced the request. Valid formats are pid, tid, and hextid. hextid requires APR 1.2.0 or higher.

%q                The query string (prepended with a ? if a query string exists, otherwise an empty string)

%r                First line of request

%R                The handler generating the response (if any).

%s                Status. For requests that got internally redirected, this is the status of the *original* request — %>s for the last.

%t                Time the request was received (standard english format)

%{format}t        The time, in the form given by format, which should be in strftime(3) format. (potentially localized)

%T                The time taken to serve the request, in seconds.

%u                Remote user (from auth; may be bogus if return status (%s) is 401)

%U                The URL path requested, not including any query string.

%v                The canonical ServerName of the server serving the request.

%V                The server name according to the UseCanonicalName setting.

%X                Connection status when response is completed:

X =                connection aborted before the response completed.

+ =                connection may be kept alive after the response is sent.

- =                connection will be closed after the response is sent.

(This directive was %c in late versions of Apache 1.3, but this conflicted with the historical ssl %{var}c syntax.)

 

%I                Bytes received, including request and headers, cannot be zero. You need to enable mod_logio to use this.

%O                Bytes sent, including headers, cannot be zero. You need to enable mod_logio to use this.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>