On Mon, 2011-04-04 at 05:05 -0700, Hongli Lai wrote:
> On Apr 4, 7:58 am, Adam Wróbel <[email protected]> wrote:
> > I'd guess it helps with handling concurrency on production systems. If you 
> > have a couple workers writing to one log file at the same time you will get 
> > messages from different requests interleaved.
> 
> Actually BufferedLogger does not protect you against inter-request
> interleaving. It only protects against inter-message interleaving.
> That is, if one thread calls Rails.logger.info("hello") and another
> calls Rails.logger.info("world") then you will either get "helloworld"
> or "worldhello", but not "helworldlo". This is all the guarantees that
> it gives. To prevent inter-request interleaving one will need to
> buffer the entire request's logger output and print everything at
> once. Something like 
> https://github.com/FooBarWidget/workling/blob/master/lib/workling/thread_local_logger.rb
> 

You don't need to buffer your own writes to protect against
inter-message interleaving.  Opening the log file in O_APPEND mode
should get you that (assuming each message is made with one write call)

John.


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to