aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/buffered_logger.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/buffered_logger.rb')
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index cedc1afe7f..6553d72b4f 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -33,11 +33,10 @@ module ActiveSupport
attr_accessor :level
attr_reader :auto_flushing
- attr_reader :buffer
def initialize(log, level = DEBUG)
@level = level
- @buffer = []
+ @buffer = {}
@auto_flushing = 1
@guard = Mutex.new
@@ -60,9 +59,7 @@ 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
- @guard.synchronize do
- buffer << message
- end
+ buffer << message
auto_flush
message
end
@@ -96,8 +93,8 @@ module ActiveSupport
def flush
@guard.synchronize do
unless buffer.empty?
- old_buffer = @buffer
- @buffer = []
+ old_buffer = buffer
+ clear_buffer
@log.write(old_buffer.join)
end
end
@@ -113,5 +110,13 @@ module ActiveSupport
def auto_flush
flush if buffer.size >= @auto_flushing
end
+
+ def buffer
+ @buffer[Thread.current] ||= []
+ end
+
+ def clear_buffer
+ @buffer[Thread.current] = []
+ end
end
end