<-
Apache > HTTP Server > �ĵ� > �汾2.2 > ģ��
���� ��л | �������� | ��ƪ���ߣ��𲽹� | ��ҳ�����£�2006��1��26�� | ��ȡ���°汾

Apacheģ�� mod_log_config

˵�������¼��־�Ͷ�����־�ļ���ʽ
״̬����(B)
ģ����log_config_module
Դ�ļ�mod_log_config.c

����

��ģ���ṩ�����ķ������ͻ������¼����־����־�������Զ���ĸ�ʽֱ��д���ļ������ߴ��͵�һ���ⲿ�����������������־���ܿ���ʵ�ָ������������������һ����־��Ϣ�Ƿ񱻰��������յ���־��¼���档

��ģ���ṩ������ָ�TransferLogָ������ָ����־�ļ���LogFormatָ������������־��ʽ��CustomLogָ�����ͬʱ���ָ����־�ļ��Ͷ�����־��ʽ��TransferLog��CustomLogָ����ÿ���������϶����Ա����ʹ�ã��Ա㽫ͬһ�������¼������ļ��С�

top

������־�ļ���ʽ

LogFormat��CustomLogָ��ĸ�ʽ��������һ���ַ���������ַ�������ÿ����������ʱ�򣬱���¼����־��ȥ�������԰�������ԭ��д����־���ı��ַ����Լ�C���Ŀ����ַ�"\n"��"\t"��ʵ�ֻ������Ʊ��ı��е����źͷ�б��Ӧͨ��"\"��ת�塣

������������ͨ���ڸ�ʽ�ַ����з��ø���"%"ת����ķ�������¼��������д����־�ļ�ʱ�������±�Ķ������ת����

��ʽ�ַ�������
%%�ٷֺ�(Apache2.0.44����ߵİ汾)
%aԶ��IP��ַ
%A����IP��ַ
%B��HTTPͷ���⴫�͵��ֽ���
%b��CLF��ʽ��ʾ�ij�HTTPͷ���⴫�͵��ֽ�����Ҳ���ǵ�û���ֽڴ���ʱ��ʾ'-'������0��
%{Foobar}C�������д��͸�����˵�cookieFoobar�����ݡ�
%D������������������ʱ�䣬��΢Ϊ��λ��
%{FOOBAR}e��������FOOBAR��ֵ
%f�ļ���
%hԶ������
%H����ʹ�õ�Э��
%{Foobar}i���͵�������������ͷFoobar:�����ݡ�
%lԶ�˵�¼��(��identd���������֧�ֵĻ�)������IdentityCheck��Ϊ"On"�����򽫵õ�һ��"-"��
%m����ķ���
%{Foobar}n������һ��ģ���ע��Foobar�����ݡ�
%{Foobar}oӦ��ͷFoobar:�����ݡ�
%p�����������ڸ�����ı�׼�˿ڡ�
%PΪ�������ṩ������ӽ��̵�PID��
%{format}P�����ڸ������PID��TID(�߳�ID)��format��ȡֵ��ΧΪ��pid��tid(2.0.46���Ժ�汾)�Լ�hextid(��ҪAPR1.2.0�����ϰ汾)
%q��ѯ�ַ���(����������һ��"?"���������򷵻ؿմ�)
%r����ĵ�һ��
%s״̬�������ڲ��ض�����������״ָ̬����ԭʼ�����״̬��---%>s��ָ������������״̬��
%tʱ�䣬����ͨ��־ʱ���ʽ(��׼Ӣ���ʽ)
%{format}tʱ�䣬��strftime(3)ָ���ĸ�ʽ��ʾ��ʱ�䡣(Ĭ������°����ػ���ʽ)
%T��������������ʱ�䣬����Ϊ��λ��
%uԶ���û���(������֤��Ϣ�������������status(%s)Ϊ401�������Ǽٵ�)
%U�����URL·������������ѯ�ַ�����
%v�Ը������ṩ����ı�׼ServerName��
%V����UseCanonicalNameָ���趨�ķ��������ơ�
%X�������ʱ������״̬��
X=������Ӧ�����ǰ�жϡ�
+=Ӧ�����������������ӡ�
-=Ӧ�������ر����ӡ�

(��1.3�Ժ�İ汾�У����ָ����%c���������ͺ͹�ȥ��SSL�﷨��%{var}c��ͻ��)

%I���յ��ֽ�������������ͷ�����ݣ����Ҳ���Ϊ�㡣Ҫʹ�����ָ�����������mod_logioģ�顣
%O���͵��ֽ�������������ͷ�����ݣ����Ҳ���Ϊ�㡣Ҫʹ�����ָ�����������mod_logioģ�顣

���η�

���Խ�����"%"�������һ�����ŷָ���״̬���б������Ƽ�¼����Ŀ�����磬"%400,501{User-agent}i"ֻ��¼״̬��400��501����ʱ��User-agentͷ���ݣ�����������ʱ��"-"���档״̬��ǰ�����Լ���"!"ǰ׺��ʾ�񶨣�"%!200,304,302{Referer}i"��¼������ͬ��200,304,302��״̬�뷢��ʱ��Refererͷ���ݡ�

"<"��">"���η���������ָ�������ѱ��ڲ��ض����������ѡ��ԭʼ��������ѡ�����յ�����Ĭ������£�%s, %U, %T, %D, %r ʹ��ԭʼ���󣬶�����������ʽ����ѡ�������������磬%>s �������ڼ�¼���������״̬���� %<u ���¼һ���Ѿ����ڲ��ض��򵽷���֤��Դ�������ԭʼ��֤�û���

һЩ˵��

���ڰ�ȫ���ǣ���2.0.46�汾��ʼ��%r, %i, %o �е������ַ�������˫����(")�ͷ�б��(\)�ֱ��� \" �� \\ ����ת�塢�հ��ַ���C���(\n, \t ��)����ת�����⣬�Ǵ�ӡ�ַ������������ַ�ʹ�� \xhh ��ʽ����ת��(hh�Ǹ��ַ���16���Ʊ���)����2.0.46��ǰ�İ汾�У���Щ���ݻᱻ�����İ�ԭ����¼���������������¿ͻ��˿�������־�в�������ַ����������ڴ�����Щ��־�ļ���ʱ��Ҫ�ر�С�ġ�

��2.0�汾��(��ͬ��1.3)��%b �� %B ��ʽ�ַ���������ʾ���͵��ͻ��˵��ֽ�������ֻ�Ǽ򵥵ı�ʾHTTPӦ���ֽ���(�������жϻ�ʹ��SSLʱ��ǰ��������ͬ)��mod_logio�ṩ�� %O ��ʽ�ַ��������¼���͵�ʵ���ֽ�����

ʾ��

һЩ�����ĸ�ʽ����

ͨ����־��ʽ(CLF)
"%h %l %u %t \"%r\" %>s %b"
������������ͨ����־��ʽ
"%v %h %l %u %t \"%r\" %>s %b"
NCSA��չ/�����־��ʽ
"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
Referer��־��ʽ
"%{Referer}i -> %U"
Agent(Browser)��־��ʽ
"%{User-agent}i"
top

��ȫ����

���������־�ļ���Ŀ¼�Գ�����Apache��������������û���д�����ܻ��ϵͳ�İ�ȫ�������в�������������μ���ȫ�������ʾ��

top

BufferedLogs ָ��

˵���ڽ���־д�����ǰ�����ڴ��н��л���
�﷨BufferedLogs On|Off
Ĭ��ֵBufferedLogs Off
������server config
״̬����(B)
ģ��mod_log_config
���������� Apache 2.0.41 ���Ժ�İ汾�п���

BufferedLogsָ��ʹ��mod_log_config�����ڴ��л���һЩ��־���ݣ�Ȼ��һ����д����̣�����������д�롣��һЩϵͳ��������������ߴ������ܡ�������ý��ܹ����ȫ�ֽ������ã����ܵ���������������������á�

����һ�������Ե�ָ�����ʹ���ж��С�ġ�
top

CookieLog ָ��

˵���趨���cookies����־�ļ���
�﷨CookieLog filename
������server config, virtual host
״̬����(B)
ģ��mod_log_config
����������ʹ�ø�ָ��

CookieLogָ��ʹ��cookies��Ϊ��־�ļ������ļ��������ServerRootĿ¼�ġ�������ָ�������Ϊ�˱�����mod_cookiesģ��ļ��ݣ����ҷ���ʹ�á�

top

CustomLog ָ��

˵���趨��־���ļ����͸�ʽ
�﷨CustomLog file|pipe format|nickname [env=[!]environment-variable]
������server config, virtual host
״̬����(B)
ģ��mod_log_config

CustomLogָ�������Է����������������־��¼������ָ����־�ĸ�ʽ��Ҳ����ʹ�û�������������������������ɵ���֯��־��

��һ������ָ������־��¼��λ�ã�����ʹ���������ַ�ʽ���趨��

file
�����ServerRoot����־�ļ�����
pipe
�ܵ���"|"���������һ������־���������׼����Ĵ������·����

��ȫ

��������õ��˳�����ô���������������httpd���û���ִ�еġ�����������httpd���û���root �����������Ҳ����root��������У�����Ҫȷ����������ǰ�ȫ�ġ�

ע��

���ڷ�UNIXƽ̨�������ļ�·����ʱ��Ҫ�ر�ע�⼴ʹƽ̨������ʹ�÷�б��(\)���ָ�·���ģ�������Ҳֻ��ʹ����б��(/)��ͨ���������ļ���ֻ����б��(/)���ָ�·�����Dz����ġ�

�ڶ�������ָ����д����־�ļ������ݡ����ȿ�������ǰ���LogFormatָ����nickname ��Ҳ������ֱ�Ӱ���־��ʽһ���������Ĺ������format�ַ�����

���磺��������ָ��Ľ������ȫһ���ģ�

# ʹ��nickname
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common

# ��ȷʹ�ø�ʽ��ʽ�ַ���
CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"

�����������ǿ�ѡ�ģ������ݷ��������ض��Ļ��������Ƿ������������Ƿ��ijһ�ض������������־��¼���������ض�����������������(������"env=!name"�������δ������)����ô������󽫱���¼��

����ʹ��mod_setenvif��/��mod_rewriteģ����Ϊÿ���������û������������磺��������ڷ������Ͻ����ж�GIFͼƬ�������¼�ڲ�ͬ������־�ļ�����һ����־�ļ��У������ʹ�������ָ�

SetEnvIf Request_URI \.gif$ gif-image
CustomLog gif-requests.log common env=gif-image
CustomLog nongif-requests.log common env=!gif-image

����Ϊ�˸��ƾ��е�RefererIgnoreָ�����Ϊ�������ʹ�������ָ�

SetEnvIf Referer example\.com localreferer
CustomLog referer.log referer env=!localreferer

top

LogFormat ָ��

˵�����������־�ļ�¼��ʽ
�﷨LogFormat format|nickname [nickname]
Ĭ��ֵLogFormat "%h %l %u %t \"%r\" %>s %b"
������server config, virtual host
״̬����(B)
ģ��mod_log_config

��ָ��������־�ļ�¼��ʽ��

LogFormatָ�����ʹ�����ֶ����ʽ�е�һ�֡��ڵ�һ�ָ�ʽ�У�ָ��ֻ��һ���������Զ��������TransferLogָ������־��ʽ�����Ψһ�IJ������԰������Զ�����־��ʽС����������format�����塣������Ҳ����ͨ�������ķ���ʹ��nickname������ij��֮ǰ��LogFormat�������־��ʽ��

�ڶ��ֶ���LogFormatָ��ĸ�ʽ�У���һ��ֱ�ӵ�format��һ��nickname��ϵ�����������ں�����LogFormat��CustomLogָ���У��Ͳ���һ���ظ������߳��ĸ�ʽ�������������LogFormatָ�������������һ��nickname �������������κ�������Ҳ����˵����ֻ���������������������û��ʵ��Ӧ�����������Ҳ���ǰ�����ΪĬ�ϵĸ�ʽ����ˣ�������Ӱ�������TransferLogָ����⣬LogFormat������һ��������������һ��������ע�⣬�������ܰ����ٷֺ�(%)��

ʾ��

LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common

top

TransferLog ָ��

˵��ָ����־�ļ���λ��
�﷨TransferLog file|pipe
������server config, virtual host
״̬����(B)
ģ��mod_log_config

��ָ���������ֱ�Ӷ�����־��ʽ���������������־��¼�⣬��CustomLogָ������ȫ��ͬ�IJ����͹��ܡ�ʵ��Ӧ���У���־�ĸ�ʽ��������ķDZ��������LogFormatָ��ָ�������û�ж����κ���־��ʽ����ʹ��ͨ����־��ʽ��

ʾ��

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
TransferLog logs/access_log