特定のログを別ファイルで記録する
アクセスログとして保存するファイルは1つだけではありません。複数のログフォーマットを定義して別々のアクセスログとして保存することも可能です。
デフォルトで「httpd.conf」ファイルに記述されているログフォーマットに「User-Agent」だけ別に記録するフォーマットを追加してみます。
LogFormat "%h %l %u %t ¥"%r¥" %>s %b ¥"%{Referer}i¥" ¥"%{User-Agent}i¥"" combined
LogFormat "%h %l %u %t ¥"%r¥" %>s %b" common
LogFormat "%{User-Agent}i" agent
そしてログファイルの指定で新しい「CustomLog」を指定します。
#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
CustomLog logs/access.log common
#
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
#CustomLog logs/access.log combined
CustomLog logs/agent.log agent
これで「User-Agent」だけ別のアクセスログファイル「agent.log」に記録されるようになります。
それでは「httpd.conf」ファイルを編集後にApacheを再起動してから、Apacheに適当にアクセスしログを見てください。
従来アクセスログを記録していた「access.log」ファイルとは別に新しく「agent.log」と言うファイルが新規に作成され、ファイルの中にはアクセスしてきたブラウザに関する情報だけが記載されています。
今回は「InternetExplorer」「Opera」「FireFox」の3つのブラウザでそれぞれApacheで公開されているHTMLファイルを閲覧した場合です。
( Written by Tatsuo Ikura )