Skip to content

Instantly share code, notes, and snippets.

@david-pm
Created December 9, 2018 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-pm/74ca9e1f75f0c751bc66671c001459ed to your computer and use it in GitHub Desktop.
Save david-pm/74ca9e1f75f0c751bc66671c001459ed to your computer and use it in GitHub Desktop.
clear dev logs on app boot
return unless 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 "---------- \033[32m clearing dev logs \033[0m --------------"
`rails log:clear`
end
@david-pm
Copy link
Author

david-pm commented Dec 9, 2018

throw this under config/initializers/clear_logs.rb

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