やりたいこと
httpd(apache2.4)がブラウザに返却するコンテンツのヘッダ情報(Content-type)や処理時間が知りたい。
- ”Content-Type"を知ることで、Deflateする対象がわかったり(ここで利用)
- 処理時間がわかることで、プログラムの遅延対象が判明する
実現手順
コンフィグファイル修正
Customlogで指定しているフォーマット(今回の例ではcombined)のLogFormatディレクティブに追記する。
httpd.conf(修正前)
...
<IfModule log_config_module>
...
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
...
CustomLog "logs/access_log" combined
</IfModule>
...
| フォーマット | 説明 |
|---|---|
| %D | リクエストを処理するのにかかった時間、マイクロ秒単位(今回はこっちを採用) |
| %T | リクエストを処理するのにかかった時間、秒単位 |
| %{Content-Type}o | 応答のヘッダの Content-Type: の中身 |
httpd.conf(修正後)
...
<IfModule log_config_module>
...
LogFormat "%h %l %u %t \"%r\" %>s %b %D \"%{Content-Type}o\" \"%{Referer}i\" \"%{User-Agent}i\"" combined
...
CustomLog "logs/access_log" combined
</IfModule>
...
再起動
# service httpd restart
参考
LogFormatに記載するフォーマットが多数記載されています。用途に応じて利用しましょう。