Rails 开发环境日志过大时自动清理
新建文件:config/initializers/clear_logs.rb
例:开发模式下当日志大于10m时自动清理
# config/initializers/clear_logs.rb if Rails.env.development? MAX_LOG_SIZE = 10.megabytes logs = [ File.join(Rails.root, 'log', 'development.log'), File.join(Rails.root, 'log', 'test.log') ] logs.each do |log| if File.size?(log).to_i > MAX_LOG_SIZE $stdout.puts "Removing Log: #{log}" `rm #{log}` end end end