phpstudy開啟apache日志并且按照日期劃分建立。
CustomLog "|bin/rotatelogs.exe logs/access_%Y_%m_%d.log 86400 480" combined

這裡修改成上圖所示,然後重新開機apache。
linux : |/usr/local/sbin/cronolog /web/apache/logs/%Y%m%daccess_log
<IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
TransferLog "|/usr/local/sbin/cronolog /web/apache/logs/%Y%m%daccess_log"
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#CustomLog "logs/access_log" combined
</IfModule>
Apache日志按時間分段記錄
在apache的配置檔案httpd.conf中找到
ErrorLog logs/error_log及CustomLog logs/access_log common
Linux系統配置方法:
将其改為
ErrorLog “| /usr/local/apache/bin/rotatelogs /home/logs/www/%Y_%m_%d_error_log 86400 480″
CustomLog “| /usr/local/apache/bin/rotatelogs /home/logs/www/%Y_%m_%d_access_log 86400 480″ common
Windows系統下配置方法:
ErrorLog “|bin/rotatelogs.exe logs/site1/error-%y%m%d.log 86400 480″
CustomLog “|bin/rotatelogs.exe logs/site1/access-%y%m%d.log 86400 480″ common
第一次不知道設定480這個參數,導緻日志記錄時間和伺服器時間相差8小時,原來是rotatelogs有一個offset參數,表示相對于UTC的時差分鐘數,中國是第八時區,相差480分鐘。86400是表示1天。
參考連結:http://www.server110.com/apache/201309/1869.html