aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/buffered_logger.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-08-18 23:33:46 -0500
committerJoshua Peek <josh@joshpeek.com>2008-08-18 23:36:13 -0500
commit96ab01e8f2b5a4475453acf60f9cf9bd8cd98483 (patch)
tree6bf2233365025492b6ec20bd74dd95f287fe3c5e /activesupport/lib/active_support/buffered_logger.rb
parentc1a8690d582c08777055caf449c03f85b4c8aa4b (diff)
downloadrails-96ab01e8f2b5a4475453acf60f9cf9bd8cd98483.tar.gz
rails-96ab01e8f2b5a4475453acf60f9cf9bd8cd98483.tar.bz2
rails-96ab01e8f2b5a4475453acf60f9cf9bd8cd98483.zip
Maintain a seperate buffer for each thread
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