依日期建立 Log 檔

1 篇文章 / 0 new
author
依日期建立 Log 檔

Apache log 分割處理用的 mod_log_rotate 此法僅適用於 CustomLog 檔(TransferLog, LogFormat and CookieLog 應也可以)

下載 mod_log_rotate.so

用法很簡單:

將 mod_log_rotate.so 放到 Apache 的 module 目錄,如 Apache2\modules.
在 httpd.conf 中加上

LoadModule log_rotate_module modules/mod_log_rotate.so
RotateLogs On (打開 log)
RotateLogsLocalTime On (用 local time 算,default 是用 UTC 時間)
RotateInterval 86400 (86400 是 default,也就是一天,這一行不加也可以)

修改 CustomLog   的地方

CustomLog logs/access.log common

改成

CustomLog logs/access_%Y%m%d.log combined


下載 cronolog 作 Apache log 的分割處理 此法僅適用於errorLog 檔 ,(CustomLog 測試無效原因??)

方法, 修改 Apache 設定檔 httpd.conf, 把 default 的

ErrorLog "logs/error.log"

改成

ErrorLog "|c:/bin/cronolog.exe logs/error_%Y%m%d.log"

就好了. 其中 c:/bin/cronolog.exe (這個是 win32 用的) 就是放 cronolog 的目錄, 後面的 logs/access_%Y%m%d.log 是 log 產出的目錄 (logs) 及形式, access_%Y%m%d.log 會生出像 access_20050702.log 這樣的檔名, 每天一個檔案. 別忽略了一開始的 “|” 那是 pipeline 給 cronolog 作處理的意思.

cronolog 詳細參數意義:

SpecifierDescription
%% a literal % character
%n a new-line character
%t a horizontal tab character
[B]Time fields[/B]
%H hour (00..23)
%I hour (01..12)
%p the locale’s AM or PM indicator
%M minute (00..59)
%S second (00..61, which allows for leap seconds)
%X the locale’s time representation (e.g.: "15:12:47")
%Z time zone (e.g. GMT), or nothing if the time zone cannot be determined
[B]Date fields[/B]
%a the locale’s abbreviated weekday name (e.g.: Sun..Sat)
%A the locale’s full weekday name (e.g.: Sunday .. Saturday)
%b the locale’s abbreviated month name (e.g.: Jan .. Dec)
%B the locale’s full month name, (e.g.: January .. December)
%c the locale’s date and time (e.g.: "Sun Dec 15 14:12:47 GMT 1996")
%d day of month (01 .. 31)
%j day of year (001 .. 366)
%m month (01 .. 12)
%U week of the year with Sunday as first day of week (00..53, where week 1 is the week containing the first Sunday of the year)
%W week of the year with Monday as first day of week (00..53, where week 1 is the week containing the first Monday of the year)
%w day of week (0 .. 6, where 0 corresponds to Sunday)
%x locale’s date representation (e.g. today in Britain: "15/12/96")
%y year without the century (00 .. 99)
%Y year with the century (1970 .. 2038)



 

Free Web Hosting