LoginSignup
5
6

More than 5 years have passed since last update.

Apache の LogFormat の変更

Last updated at Posted at 2012-08-03

LogFormat の変更

httpd.conf
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" common
(中略)
CustomLog "logs/access_log" combined

のように記述されている箇所に

httpd.conf
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h\t%l\t%u\t%t\t\"%r\"\t%>s\t%b\t\"%{Referer}i\"\t\"%{User-Agent}i\"\t%D" combined_tsv
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" common
(中略)
CustomLog "logs/access_log" combined_tsv

combined_tsvを追記する。
こうすると今までスペースだったdelimiterがタブになるので解析が容易になる。

変更後のログは

127.0.0.1 -       -       [03/Aug/2012:13:01:15 +0900]    "POST /search/? HTTP/1.1"       200     172     "-"     "Python-urllib/2.6"     627276
127.0.0.1 -       -       [03/Aug/2012:13:01:14 +0900]    "POST /demo HTTP/1.1"   200     29802   "http://xxxx/demo"     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25"     1570131

の形式で出力されるようになる。

CustomLog書式は
http://httpd.apache.org/docs/2.2/ja/mod/mod_log_config.html#formats
にまとまっている。

log の読み方

出力されたログを便宜上9つの部分に分割する

  1. 127.0.0.1
  2. - -
  3. [03/Aug/2012:11:28:21 +0900]
  4. POST /search/? HTTP/1.1
  5. 200
  6. 47912
  7. "-"
  8. Python-urllib/2.6
  9. 0

この出力された9つの部分は次のような意味を表している。

--

ログの内容

1.IPアドレスまたはリモートホスト名

125.100.190.246

2.identによるリモートユーザー名と認証時のユーザー名。

- -

3.アクセス日時

[03/Aug/2012:11:28:21 +0900]

4.リクエストヘッダー・ファイル名・プロトコルバージョン。GETはGET方式での呼び出し、POSTはPOST方式の呼び出しになる。

POST /search/? HTTP/1.1

5.ステータスコード

200

6.転送されたバイト数。これにはヘッダ行は含まれていない。

47912

7.呼び出し元のURL

"-"

8.ユーザーエージェント

Python-urllib/2.6

9.リクエストを処理するのにかかった時間(マイクロ秒単位)

0

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6