Can I simply delete the log files?

"Jon Collier" wrote:

Joshua Muheim wrote:
> Hi there
>
> I wanted to upload a Rails app and saw that the log files are 16mb big!
> Can I simply delete them? Will Rails create automatically new ones when
> needed? Or do I have to empty them so they aren't that big anymore...?
>
> Thanks for info.
> Josh

You can include this in your environment.rb file:
<code>RAILS_DEFAULT_LOGGER =
Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", 20, 10.megabyte)
</code>

Put it beneath the line: require File.join(File.dirname(__FILE__),
'boot')

This line will make rails automatically rotate your logs. In this
instance, it will rotate the log whenever it hits 10 megabytes, and it
will keep the most recent 20 files.

I just want to add that the above code works very well in development.
However, in production it causes the rails app to die with error code 500.

Further investigation show when rotate is triggered, rails looses complete
access to the production.log file. I just found out how sensitive rails is not
able to write to its log. In my case Apache logged a dispatcher.fcgi error
due to sending incomplete header information (35 bytes).

So why is rails so sensitive about the log file? Can or should this be changed
to fail write quietly or less violent?

What other ways to rotate the log file, safely?

Thanks for your insight,

Long