Skip to content

Instantly share code, notes, and snippets.

@mikeatlas
Last active February 28, 2021 14:39
Show Gist options
  • Save mikeatlas/6157000 to your computer and use it in GitHub Desktop.
Save mikeatlas/6157000 to your computer and use it in GitHub Desktop.
automatically clear rails development logs on startup if they're too big
# config/initializers/clear_logs.rb
# This snippet simply clears your logs when they are too large.
# Every time you start the rails environment it checks log sizes
# and clears the logs for you if necessary.
if Rails.env.development?
MAX_LOG_SIZE = 10.megabytes
logs = File.join(Rails.root, 'log', '*.log')
if Dir[logs].any? {|log| File.size?(log).to_i > MAX_LOG_SIZE }
$stdout.puts "Development log files too large. Running rake log:clear"
`RAILS_ENV=development rake log:clear`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment