468x60廣告120x60 廣告
  加入我的最愛 設為首頁 即時聊天 樣式:樣式: 展開
首頁 首尾
 PDA   訂閱   地圖 
您是第 2392 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
月光 男 獅子座 0935-XXXXXX
個人頭像
個人首頁 個人文章 145 篇 個人相簿 25 篇 個人日記 2 篇 個人地圖
社區建設獎
頭銜:看我代替月亮懲罰你!看我代替月亮懲罰你!
版主
級別: 版主 該用戶目前不上站
版區: Unix-like, 網站架設
發表文章: 145 (165)
回覆文章: 774 (791)
威望: 249
雅幣: 40567
存款: 30000
財富: 玉樓銀海
金幣: 0 (購買金幣)
推薦 x39 鮮花 x554

發送私人訊息 引用回覆這個文章 複製連結到剪貼簿 轉換為繁體 轉換為簡體 分享到自己的facebook
推薦 推薦 x0
[其他][教學] 使用 cronolog 作 Apache log 的分割處理

使用 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.saab.club.tw/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) 及形式, access_%Y%m%d.log 會生出像 access_20050702.log 這樣的檔名, 每天一個檔案. 別忽略了一開始的 “|” 那是 pipeline 給 cronolog 作處理的意思.

你也許會問: 啊留 Apache 的 log 要作什麼? 用途多者呢, 一來出問題的時候可以查問題, 像上次的盜連事件; 二來可以交給後端的 log 分析程式, 如免費的 awstats, 統計看看有多少人看你的網頁、每天流量、每小時流量比較、他們從哪裡來、用什麼樣的字詞從搜尋引擎搜尋到你的網頁等等等… 有很多好玩的! 例如這個可以看2005年六月份用戶來自國家的統計, 好多奇奇怪怪的國家 、2005年六月份用戶端瀏覽器的使用率; 嗯,Firefox還是要多加油,一直只在8%~10%左右;.

cronolog 詳細參數意義:

SpecifierDescription
%%a literal % character
%na new-line character
%ta horizontal tab character
[B]Time fields[/B]
%Hhour (00..23)
%Ihour (01..12)
%pthe locale’s AM or PM indicator
%Mminute (00..59)
%Ssecond (00..61, which allows for leap seconds)
%Xthe locale’s time representation (e.g.: "15:12:47")
%Ztime zone (e.g. GMT), or nothing if the time zone cannot be determined
[B]Date fields[/B]
%athe locale’s abbreviated weekday name (e.g.: Sun..Sat)
%Athe locale’s full weekday name (e.g.: Sunday .. Saturday)
%bthe locale’s abbreviated month name (e.g.: Jan .. Dec)
%Bthe locale’s full month name, (e.g.: January .. December)
%cthe locale’s date and time (e.g.: "Sun Dec 15 14:12:47 GMT 1996")
%dday of month (01 .. 31)
%jday of year (001 .. 366)
%mmonth (01 .. 12)
%Uweek 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)
%Wweek 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)
%wday of week (0 .. 6, where 0 corresponds to Sunday)
%xlocale’s date representation (e.g. today in Britain: "15/12/96")
%yyear without the century (00 .. 99)
%Yyear with the century (1970 .. 2038)




月光論壇
http://bbs.djorz.com/



===================================
贊助本站 -- 刊登廣告 -- 物超所值虛擬主機租用
點歌 回到頂端 [樓 主] From:臺灣中華電信HINET | Posted:2008-03-25 06:09 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.041234 second(s),query:12 Gzip enabled
本站由 簡榮宗律師 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言