2013年11月14日木曜日

アクセスされるURLによってログファイルを分ける

Apache でアクセスされるURLによってログファイルを分けたかったので調べた。
ログの設定はよく以下の感じで書いてある。
CustomLog logs/access_log combined
これを例えば /hoge/ 以下にアクセスされたものを別のファイルに出したい時は
SetEnvIf Request_URI "/hoge/" hogelog
CustomLog logs/hoge.log combined env=hogelog
みたいな感じでいける。
ただこれだと access_log の方にもログが出るので、そっちに出したくない場合は
CustomLog logs/access.log combined env=!hogelog
とかしてやるといい。
あとは SetEnvIf は複数指定出来るので
SetEnvIf Request_URI "/hoge/" hogelog
SetEnvIf Request_URI "/fuga/hoge/" hogelog
CustomLog logs/hoge.log combined env=hogelog
とか
SetEnvIf Request_URI "/hoge/" hogelog other
SetEnvIf Request_URI "/fuga/" fugalog other
CustomLog logs/access.log combined env=!other
CustomLog logs/hoge.log combined env=hogelog
CustomLog logs/fuga.log combined env=fugalog
とかも出来る。

0 件のコメント:

コメントを投稿