diff options
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 |