使用 Apache, 它的 log 檔 default 是叫 access.log, 是一個連續且不斷長大的檔案, 只要 log 不是關閉狀態, 凡是用戶連向你的網站, 就會有像這樣的一筆記在 log:192.168.0.2 - - [01/Jul/2005:17:22:04 +0800] "GET /wp/archives/2005/06/27/12/28/41/ HTTP/1.1" 200 9760 "http://www./guestbook/guestcontent.asp?TopicID=1363&Board_Level=3" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
依序是用戶 IP, 時間, 動作, 回覆碼, 回傳資料大小(bytes), referer(從什麼地方連過來), 用戶端瀏覽器資料;後端 log 分析程式可以依此計算出計多有趣的統計.
但是一個連續且不斷長大的 log 檔是不方便使用、管理和備份的, 最好是可以依照某種方法把檔案作分割. cronolog 就是因應這樣的需求而生的, 它可以在 win32 或 unix 平台運作, 這裡可以下載.
使用的方法也很簡單, 只要修改你的 Apache 設定檔 httpd.conf, 把 default 的CustomLog logs/access.log combined
改成CustomLog "|c:/bin/cronolog.exe logs/access_%Y%m%d.log" combined
就好了. 其中 c:/bin/cronolog.exe (這個是 win32 用的) 就是你放 cronolog 的目錄, 後面的 logs/access_%Y%m%d.log 是 log 產出的目錄 (logs) 及形式1, access_%Y%m%d.log 會生出像 access_20050702.log 這樣的檔名, 每天一個檔案. 別忽略了一開始的 "|" 那是 pipeline 給 cronolog 作處理的意思.
你也許會問: 啊留 Apache 的 log 要作什麼? 用途多者呢, 一來出問題的時候可以查問題, 像上次的盜連事件; 二來可以交給後端的 log 分析程式, 如免費的 awstats, 統計看看有多少人看你的網頁、每天流量、每小時流量比較、他們從哪裡來、用什麼樣的字詞從搜尋引擎搜尋到你的網頁等等等… 有很多好玩的呢! 例如這個可以看2005年六月份用戶來自國家的統計, 好多奇奇怪怪的國家 、2005年六月份用戶端瀏覽器的使用率,本月用戶來自國家的統計、本月用戶端瀏覽器的使用率,都是定時自動更新,有興趣的話可以常常來看一下變化; 嗯,Firefox還是要多加油,一直只在8%~10%左右;.
- cronolog 詳細參數意義:[back]
Specifier Description %% a literal % character %n a new-line character %t a horizontal tab character Time fields %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 Date fields %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)
July 2nd, 2005 at 9:20 pm 1
不知道用虛擬主機看不看得到 log ?
July 2nd, 2005 at 11:42 pm 2
以前的工作,同事請假時我就要幫忙看這一大堆 web server 的 log, 以前都是直接在 unix 下直接用 vi 看上面那一堆亂七八糟的文字,有看或許等於沒看,根本就是讓人看得眼花撩亂而已。
時代「一天天」地在進步,現在將 log 檔整理為這種一目瞭然的報表,真是系統管理員的一大福音啊!
September 3rd, 2005 at 9:51 pm 3
太好了~但我是初學者~可以更詳細的說明怎麼安裝使用嗎~~謝謝啦~~~
September 3rd, 2005 at 9:52 pm 4
補充一下~我是用freebsd…
September 3rd, 2005 at 9:55 pm 5
已經很簡單了說,哪裡看不懂? 用了就知道.
April 28th, 2006 at 6:48 pm 6
[…] Apache 的 log 動輒幾十 MB,不要說從裡面翻出有用的資料來作分析,光打開檔案就是件麻煩事了。Mark 在 使用 cronolog 作 Apache log 的分割處理 提到利用 cronolog 將 Apache 的 log 依日期切開,不僅方便檢視也容易管理。試用了一下果真如 Mark 所說的那麼簡單,access.log 變成 access_20060428.log,跟以往土法煉鋼的方法相比省去不少功夫。 […]
July 13th, 2006 at 6:57 pm 7
如果我用的是虚拟主机请问怎么设置啊
我对程序不太懂
谢谢