如何delete delelopment logs


Deleting development.log if it Reaches a Certain File Size

Maybe you want to keep the development.log file around unless it reaches a certain file size. If that’s the case, we can tweak what we previously added in config/environments/development.rb:


# delete local dev logs after exiting
at_exit do
  development_logfile = Rails.application.config.paths['log'].first

  if File.exist?(development_logfile)
    # get file size of development.log and convert to Megabytes rounded to 2 decimal places
    file_size = (File.size(development_logfile) / 1_024_000.0).round(2)

    # if development.log is 50MB or more, delete it.
    if file_size >= 50
      Rails.logger.debug 'development.log is over 50MB. Deleting...'
      File.delete(development_logfile)
    end
  end
end

阅读量: 583
发布于:
修改于: