aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-26 10:41:59 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-26 10:41:59 -0700
commite28f9ad9df6c3b1a51db7ced3af781d114486aec (patch)
tree84031644521b4431dcf3f7fdd3d289579c15f1e7 /activesupport/lib
parent315f5557441a826666e91936ce01675ee77bd40f (diff)
downloadrails-e28f9ad9df6c3b1a51db7ced3af781d114486aec.tar.gz
rails-e28f9ad9df6c3b1a51db7ced3af781d114486aec.tar.bz2
rails-e28f9ad9df6c3b1a51db7ced3af781d114486aec.zip
simplifying buffered logger for easier and slightly more performant codes. pumpkin
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb13
-rw-r--r--activesupport/lib/active_support/log_subscriber.rb2
2 files changed, 5 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index e41731f3e7..88b50fc506 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -41,7 +41,7 @@ module ActiveSupport
def initialize(log, level = DEBUG)
@level = level
- @buffer = {}
+ @buffer = Hash.new { |h,k| h[k] = [] }
@auto_flushing = 1
@guard = Mutex.new
@@ -100,13 +100,8 @@ module ActiveSupport
def flush
@guard.synchronize do
- unless buffer.empty?
- old_buffer = buffer
- all_content = StringIO.new
- old_buffer.each do |content|
- all_content << content
- end
- @log.write(all_content.string)
+ buffer.each do |content|
+ @log.write(content)
end
# Important to do this even if buffer was empty or else @buffer will
@@ -127,7 +122,7 @@ module ActiveSupport
end
def buffer
- @buffer[Thread.current] ||= []
+ @buffer[Thread.current]
end
def clear_buffer
diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb
index 10675edac5..1c4dd24227 100644
--- a/activesupport/lib/active_support/log_subscriber.rb
+++ b/activesupport/lib/active_support/log_subscriber.rb
@@ -81,7 +81,7 @@ module ActiveSupport
# Flush all log_subscribers' logger.
def flush_all!
- flushable_loggers.each(&:flush)
+ flushable_loggers.each { |log| log.flush }
end
end