LoginSignup
0
0

More than 1 year has passed since last update.

古いlogを削除する方法

Posted at

背景

開発するときにdevelopment.logやproduction.log等の中身を容量が大きくならないように消そうと思った。

1.普通にファイルを消す方法

rm log/production.log 

で消してwebサーバを再起動させる。

2.自動で定期的に消させる方法

次はlogrotateでログローテーションを行う方法です。
まずファイルを以下のパスで作成します。

sudo touch /etc/logrotate.d/rails

作成したファイルにlogrotateの設定を記述します。

/var/www/autovice/current/log/*log {
  daily
  missingok
  rotate 30
  dateext
  dateformat _%Y%m%d
  compress
  copytruncate
  ifempty
  su user user
}

次にちゃんと設定したものが実行されるのかテストします。

sudo /usr/sbin/logrotate -d /etc/logrotate.d/rails

logrotateの詳しい記述方法は以下のURLから見れます。
https://milestone-of-se.nesuke.com/sv-basic/linux-basic/logrotate/

0
0
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
0
0