# Production Logging with Rails 2.2.2

**URL:** <https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606>\
**Category:** Rails\
**Created:** [March 11, 2009, 9:32pm UTC](https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606 "2009-03-11T21:32:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 11, 2009, 9:32pm UTC](https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606/1 "2009-03-11T21:32:30Z")

</div>

I’m having an issue with logging when I run my Rails app in production  
mode:

script/console production  
Loading production environment (Rails 2.2.2)

> > Rails.logger  
> > =\> #\<ActiveSupport::BufferedLogger:0x24e46c8 @auto\_flushing=1000,  
> > @log=#\<File:log/production.log\>, @buffer={#\<Thread:0x35700 run\>=\>[“My  
> > logged message\n”]}, @guard=#Mutex:0x24c0688, @level=0\>
> 
> > Rails.logger.error(“hello!”)  
> > =\> “hello!\n”
> 
> > Rails.logger  
> > =\> #\<ActiveSupport::BufferedLogger:0x24e46c8 @auto\_flushing=1000,  
> > @log=#\<File:/Users/tom/Sites/buzzsprout/log/production.log\>, @buffer=  
> > {#\<Thread:0x35700 run\>=\>[“Mylogged message\n”, “hello!\n”]},  
> > @guard=#Mutex:0x24c0688, @level=0\>

For some reason, messages are not being written to the log when I use  
the logger.error or logger.info methods. They appear in the  
Rails.logger @buffer?

Anyone have any ideas?

Thanks!  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 11, 2009, 9:37pm UTC](https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606/2 "2009-03-11T21:37:12Z")

</div>

Its worth noting that the system logs just fine, it is just my logger  
messages that get stuck in the buffer. If I run Rails.logger.flush  
from the console, the messages are written correctly to the production  
log. Weird.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 11, 2009, 11:58pm UTC](https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606/3 "2009-03-11T23:58:42Z")

</div>

On Mar 11, 8:36 pm, tomrossi7 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Its worth noting that the system logs just fine, it is just my logger  
> messages that get stuck in the buffer. If I run Rails.logger.flush  
> from the console, the messages are written correctly to the production  
> log. Weird.

The buffered log only hits disk when its flushed (which occurs either  
when more than X has been logged or as part of the request cycle),  
which isn’t going to happen by itself when you’re running from the  
console. Not sure what else you can do other than ensure that flush is  
called at some point.

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 12, 2009, 4:04am UTC](https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606/4 "2009-03-12T04:04:59Z")

</div>

I got my logging to start working by adding the following to the end  
of my environment.rb file:

Rails.logger.auto\_flushing =1

I wonder if there is an issue with Rails 2.2.2 flushing the log  
buffer?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 12, 2009, 1:38am UTC](https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606/5 "2009-03-12T01:38:10Z")

</div>

Interesting i am having the same issue with Jruby/Tomcat. Nothing is  
getting logged to localhost-YYYY-MM-DD.log files at all after a period  
of time.

Is there no way to set the buffer threshold to force a flush on every  
log ?

Adam

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 13, 2009, 4:34am UTC](https://www.ruby-forum.com/t/production-logging-with-rails-2-2-2/162606/6 "2009-03-13T04:34:11Z")

</div>

i can say for sure there is at least with Jruby/Tomcat running Rails.  
did this only effect you in production ?
