LoginSignup
6
5

More than 5 years have passed since last update.

logrotateのファイル名に一意な値を入れたい

Posted at

某社のアプリで、ログを分割して開きやすくしよう、というのをやっているんだけど、その際にlogrotateを利用している。
で、デフォルトだと以下の様な感じになる。

production.log
production.log.1
production.log.2
production.log.3

良い。良いんだけど、3とかまでいくと滅多に見ないし、圧縮したいよね、とか、1,2,3だといつのやつなのかいまいち判別付かない、とか、そういう運用面で困ったことがままある。
ので、これを良い感じにしてみようと思う。

圧縮する

/etc/logrotate.d/appみたいなファイルに、以下のオプションを入れる。

/var/www/app/shared/log/production.log {
  delaycompress
  compress
}

こうすると、

production.log
production.log.1
production.log.2.gz
production.log.3.gz

となる。あらべんり。

連番じゃなくて日付にする

/var/www/app/shared/log/production.log {
  delaycompress
  compress
  dateext
}

こうすると、

production.log
production.log.2014-05-21
production.log.2014-05-20.gz
production.log.2014-05-19.gz

となる。あらべんり。

まとめ

古いファイルは消すか、Amazon Glacierに転送するのが良いと思います。

6
5
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
6
5