Skip to content

Instantly share code, notes, and snippets.

@bloc40
Last active October 1, 2015 14:47
Show Gist options
  • Select an option

  • Save bloc40/7a80bb270c3413d02bc2 to your computer and use it in GitHub Desktop.

Select an option

Save bloc40/7a80bb270c3413d02bc2 to your computer and use it in GitHub Desktop.
Clear your development logs automatically when they are too large
# config/initializers/clear_logs.rb

if Rails.env.development?
  MAX_LOG_SIZE = 2.megabytes
  
  logs = File.join(Rails.root, 'log', '*.log')
  if Dir[logs].any? {|log| File.size?(log).to_i > MAX_LOG_SIZE }
    $stdout.puts "Runing rake log:clear"
    `rake log:clear`
  end 
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment