apache2日誌格式

ubuntu 16.04中,默認的apache2配置文件位於

/etc/apache2/apache2.conf

其中可以找到LogFormat語法,定義了日誌格式如下:

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

站點的配置位於

/etc/apache2/sites-available/000-default.conf

其中,關於日誌有這麼兩句配置

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

其中,combined別名就指定了該站點日誌所採用的格式。該格式中各字段的含義如下:

字段 含義
%h 請求來源主機
%l 遠程日誌名稱(一般默認爲橫槓)
%u 遠程用戶(一般默認爲橫槓)
%t 收到請求的時間
%r HTTP請求第一行
%>s 請求最終狀態
%O 發送出去的字節數目
%{VARNAME}i HTTP請求頭中VARNAME字段內容


另外,我們通常比較關注每個請求的處理時間,可以添加一個字段 %D,顯示每個請求的處理時間,以微秒爲單位。另外一個功能相同的字段是%T,不過是以秒爲單位。

LogFormat "%h %l %u %t \"%r\" %>s %O %D \"%{Referer}i\" \"%{User-Agent}i\"" combined

更多配置細節,可以參考官方網站

參考

Apache Module mod_log_config

What is the default apache2 log format and where is defined such default?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章