Ruby on rails log file size too large

前端 未结 9 1334
无人共我
无人共我 2021-02-01 16:01

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,

相关标签:
9条回答
  • 2021-02-01 16:29

    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/

    0 讨论(0)
  • 2021-02-01 16:38

    config.logger = ActiveSupport::Logger.new(nil) does the trick and completely disables logging to a file (console output is preserved).

    0 讨论(0)
  • 2021-02-01 16:38

    A fair compromise, in an initializer:

    Rake::Task['log:clear'].invoke if Rails.env.development? || Rails.env.test?
    
    0 讨论(0)
提交回复
热议问题