# Can I simply delete the log files?

**URL:** <https://www.ruby-forum.com/t/can-i-simply-delete-the-log-files/68810>\
**Category:** Rails\
**Created:** [September 15, 2006, 4:18pm UTC](https://www.ruby-forum.com/t/can-i-simply-delete-the-log-files/68810 "2006-09-15T16:18:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [September 15, 2006, 4:18pm UTC](https://www.ruby-forum.com/t/can-i-simply-delete-the-log-files/68810/1 "2006-09-15T16:18:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [September 15, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/can-i-simply-delete-the-log-files/68810/2 "2006-09-15T16:29:31Z")

</div>

Joshua M. 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:  
`RAILS_DEFAULT_LOGGER =
Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", 20, 10.megabyte)
`

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.

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [September 15, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/can-i-simply-delete-the-log-files/68810/3 "2006-09-15T16:30:28Z")

</div>

Or, if you really don’t need them, you can use:

rake clear\_logs

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [September 15, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/can-i-simply-delete-the-log-files/68810/4 "2006-09-15T16:30:41Z")

</div>

you can delete them.

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [September 24, 2006, 8:04am UTC](https://www.ruby-forum.com/t/can-i-simply-delete-the-log-files/68810/5 "2006-09-24T08:04:48Z")

</div>

“Jon C.” wrote:

> 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
