Clear Development Logs

Automatically clear development logs when they get over 2mb.
Icons/chart bar
Used 42 times
Created by
D Dale Zak

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/VZgs77"
Template Source

Review the code before running this template on your machine.

file 'config/initializers/clear_logs.rb', <<-CODE
if Rails.env.development?
  MAX_LOG_SIZE = 2.megabytes
  logs = Dir[File.join(Rails.root, 'log', '*.log')]
  logs.each do |log|
    log_size = File.size?(log).to_i
    if log_size > MAX_LOG_SIZE
      puts "Removing Log: \#{log}"
      `rm \#{log}`
    end
  end
end
CODE
Comments

Sign up or Login to leave a comment.