Use this simple gist to truncate your logs automagically. It will only touch your development.log, as I do note like when initializers pull production or staging logs into the mix, as that might be a security risk when you just needed to test a part of your app on your production environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/clear_dev_logs.rb | |
# This snippet simply clears your logs when they are too large. | |
# Large logs for development are usually something you don't want. | |
# Every time you run rails server or rails console it checks the size | |
# of your development logfile and truncates it. | |
if Rails.env.development? | |
MAX_LOG_SIZE = 1.megabytes | |
DEV_LOG_FILE = File.join(Rails.root, 'log', 'development.log') | |
if File.size?(DEV_LOG_FILE).to_i > MAX_LOG_SIZE | |
$stdout.puts "-------------------------------------------------" | |
$stdout.puts "Truncating development.log...." | |
$stdout.puts "-------------------------------------------------" | |
File.truncate(DEV_LOG_FILE, 0) | |
end | |
end |