Skip to content

Instantly share code, notes, and snippets.

@pahanix
Created March 24, 2011 19:22
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pahanix/885671 to your computer and use it in GitHub Desktop.
Save pahanix/885671 to your computer and use it in GitHub Desktop.
Clear your logs in development automatically when they are too large.
# config/initializers/clear_logs.rb
# This snippet simply clears your logs when they are too large.
# Large logs mean looooong search in TextMate. You know it :)
# Every time you run rails server or rails console it checks log sizes
# and clears the logs for you if necessary.
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
@pahanix
Copy link
Author

pahanix commented Mar 24, 2011

UPD: It will delete production logs if you mistakenly run something in dev mode on production

@chrishough
Copy link

This was super duper handy! @matt-morris check this out 😄

Copy link

ghost commented Mar 18, 2019

A useful piece

@ordinz
Copy link

ordinz commented Apr 6, 2021

Nice! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment