Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails log file size too large

I stumbled to learn that my rails3.1 log file is super large, around 21mb. Is this, in terms of size normal? What the log file would like in the production environment? Besides, can I get rid of the log?thanks

like image 410
Jason Avatar asked Oct 16 '11 11:10

Jason


5 Answers

The log folder of your Rails application holds three log files corresponding to each of the standard environments. Log files can grow very large over time. A rake task is provided to allow the easy clearing of the log files.

rake log:clear
# Truncates all *.log files in log/ to zero bytes 
# Specify which logs with LOGS=test,development,production
like image 167
Raj Adroit Avatar answered Oct 24 '22 03:10

Raj Adroit


you can just delete the file!
Rails will create a new log if one doesn't exist.
Obviously save / backup the file if it's important, but usually it's not.
You can also zip the backuped up file (and then delete the source) if you want to keep it on the same drive but still save space.

To automatically rotate log files (the best long-term solution) use log rotate as described here:

Ruby on Rails production log rotation

then you can set it and forget it!

To actually change what gets logged see:

http://dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/

like image 42
Michael Durrant Avatar answered Oct 24 '22 05:10

Michael Durrant


According to the documentation, if you want to limit the size of the log folder, put this in your 'development.rb'-file:

config.logger = ActiveSupport::Logger.new(config.paths['log'].first, 1, 50 * 1024 * 1024)

With this, your log files will never grow bigger than 50Mb. You can change the size to your own preference. The ‘1’ in the second parameter means that 1 historic log file will be kept, so you’ll have up to 100Mb of logs – the current log and the previous chunk of 50Mb.

like image 13
Fellow Stranger Avatar answered Oct 24 '22 04:10

Fellow Stranger


I automatically clear the logs in development on each server start with config/initializers/clear_development_log.rb:

if Rails.env.development?
  `rake log:clear`
end
like image 6
Drew Stephens Avatar answered Oct 24 '22 04:10

Drew Stephens


You may want to use logrotate. Have a look at the answer to this question: Ruby on Rails production log rotation.

like image 5
htanata Avatar answered Oct 24 '22 04:10

htanata