Yiiのアプリケーションエラーログは、スタックトレースや環境変数のダンプなど、記述が詳細すぎて、発生をすぐに検知したり、時間的な流れを見たりするとき、そのままでは辛いです。(詳しく調べるのには向いてるんですが)
が、うまく grep してやれば tail もできますよというシェルのテクニック、これで、たとえばエラーが出たらすぐにわかるようになったりします。
$ tail -f runtime/frontend/logs/app.log | grep --line-buffered "\[error\]"
こういう調子のが
2014-10-23 12:18:00 [111.111.111.111][1][-][error][hoge\fuga\SomeException] exception 'SomeException'
with message 'Failed to connect to: hogehoge enterprise backend' in /home/hogehoge/webapp/hoge/fuga/Connection.php:247
Stack trace:
#0 /home/hogehoge/webapp/hoge/fuga/Connection.php(247): SomeConnection->__construct('dsn://hogehoge...', Array)
#1 ...
:
:
#28 {main}
2014-10-23 12:18:00 [172.31.7.240][1][-][info][application] $_COOKIE = [
'_csrf' => 'xxxxxxxxx'
'SESSION' => 'yyyyyyyyyyyy'
'_identity' => 'zzzzzzzzzzz'
]
$_SESSION = [
'__flash' => []
'__returnUrl' => '/'
'__id' => 1
]
$_SERVER = [
'USER' => 'hogehoge'
:
:
'REQUEST_TIME' => 1414066680
]
2014-10-23 12:19:00 [111.111.111.111][1][-][error][hoge\fuga\SomeException] exception 'SomeException'
with message 'Failed to connect to: hogehoge enterprise backend' in /home/hogehoge/webapp/hoge/fuga/Connection.php:247
:
:
こういう調子になる
2014-10-23 12:18:00 [111.111.111.111][1][-][error][hoge\fuga\SomeException] exception 'SomeException'
with message 'Failed to connect to: hogehoge enterprise backend' in /home/hogehoge/webapp/hoge/fuga/Connection.php:247
2014-10-23 12:19:00 [111.111.111.112][1][-][error][hoge\fuga\SomeException] exception 'SomeException'
with message 'Failed to connect to: hogehoge enterprise backend' in /home/hogehoge/webapp/hoge/fuga/Connection.php:247
2014-10-23 12:20:00 [111.111.111.113][1][-][error][hoge\fuga\SomeException] exception 'SomeException'
with message 'Failed to connect to: hogehoge enterprise backend' in /home/hogehoge/webapp/hoge/fuga/Connection.php:247
まあ、本質的にはYiiに特化した話ではないけれど、Yiiのログを追う人のスクロール操作がやたら多いなあと感じるので、Yiiユーザーにはぜひ知っておいてもらいたい方法です。