diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-07-29 19:49:38 +0200 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-07-29 19:49:38 +0200 |
commit | a24398b64757df8c5939b07238c740bddfdab03e (patch) | |
tree | a838f8d5425137ca5cecba8a259eb40003e7c0e9 /activesupport | |
parent | 7aaf1689dda863b72623f0e52ad87e2b739cb22b (diff) | |
download | rails-a24398b64757df8c5939b07238c740bddfdab03e.tar.gz rails-a24398b64757df8c5939b07238c740bddfdab03e.tar.bz2 rails-a24398b64757df8c5939b07238c740bddfdab03e.zip |
Guard the logger's internal buffer to prevent major breakage on genuinely threaded environments
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/buffered_logger.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index 67b0a580ea..aec416a6d6 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -40,6 +40,7 @@ module ActiveSupport @buffer = [] @auto_flushing = 1 @no_block = false + @guard = Mutex.new if log.respond_to?(:write) @log = log @@ -66,7 +67,9 @@ module ActiveSupport # If a newline is necessary then create a new message ending with a newline. # Ensures that the original message is not mutated. message = "#{message}\n" unless message[-1] == ?\n - buffer << message + @guard.synchronize do + buffer << message + end auto_flush message end @@ -98,11 +101,16 @@ module ActiveSupport end def flush - unless buffer.empty? - if @no_block - @log.write_nonblock(buffer.slice!(0..-1).join) - else - @log.write(buffer.slice!(0..-1).join) + @guard.synchronize do + unless buffer.empty? + old_buffer = @buffer + @buffer = [] + text_to_write = old_buffer.join + if @no_block + @log.write_nonblock(text_to_write) + else + @log.write(text_to_write) + end end end end |