10月 012008
 

Apache 一般有两种日志格式:
通用日志格式(Common Log Format) 和 组合日志格式(Combined Log Format)

http.conf中默认格式如下:
LogFormat “%h %l %u %t \”%r\” %>s %b” common
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-agent}i\”” combined

也可以使用自定义,这里使用`分隔 日志参数

%h`%l`%u`%{%Y-%m-%d %H:%M:%S}t`%r`%s`%b`%{Referer}i`%{User-Agent}i`%{X-Up-Calling-Line-ID}i

输出结果如下:
127.0.0.1 – frank [10/Oct/2000:13:55:36 -0700] “GET /apache_pb.gif HTTP/1.0″ 200 2326
127.0.0.1 – frank [10/Oct/2000:13:55:36 -0700] “GET /apache_pb.gif HTTP/1.0″ 200 2326 “http://www.example.com/start.html” “Mozilla/4.08 [en] (Win98; I ;Nav)”
172.16.0.115`-`-`2008-03-13 11:00:03`GET /logo.gif HTTP/1.1`200`2893`http://172.16.0.252/index.jsp `Opera/9.26 (Windows NT 5.1; U; zh-cn)`- Continue reading »

10月 012008
 

对于PHP开发人员来说,一旦某个产品投入使用,那么第一件事就是应该将display_errors选项关闭,以免因为这些错误所透露的路径、数据库连接、数据表等信息而遭到黑客攻击。

某个产品投入使用后,难免会有错误信息,那么如何记录这些对开发人员非常有用的信息呢?

将PHP的log_errors开启即可,默认是记录到WEB服务器的日志文件里,比如Apache的error.log文件。

当然也可以记录错误日志到指定的文件中。

# vim /etc/php.ini
display_errors = Off
log_errors = On
error_log = /var/log/php-error.log

另外也可以设定error_log = syslog,使这些错误信息记录到操作系统的日志里。

9月 092008
 

access.log,件在 WEB 服务器运行一段时间之后会达到几十兆甚至上百兆,如果Apache运行有错误,error.log也会增大到几十兆,我们知道系统读写一个大的文本文件是非常耗内存的,因此限定日志文件大小十分必要。

通常我们是在{$apache}/conf/httpd.conf中设置Apache的参数,然而我们并没有发现可以设置日志文件大小的配置指令,通过参考http://httpd.apache.org/docs/2.0/programs/rotatelogs.html,可以用apache 自己的程序 rotatelogs.exe(位于 {$apache}/bin/目录下),来限制日志文件的大小。

Usage: rotatelogs [-l] [offset minutes from UTC] or

Add this:
TransferLog “|rotatelogs /some/where 86400”  
or
TransferLog “|rotatelogs /some/where 5M”
to httpd.conf. The generated name will be /some/where.nnnn where nnnn is the system time at which the log nominally starts (N.B. if using a rotation time, the time will always be a multiple of the rotation time, so you can synchronizecron scripts with it). At the end of each rotation time or when the file size is reached a new log is started.

在 Windows 下的设置例子如下: Continue reading »