diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/tagged_logging.rb | 46 | ||||
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 6 |
2 files changed, 33 insertions, 19 deletions
diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index 6af87e85e6..7e7f7ecfb2 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -15,16 +15,27 @@ module ActiveSupport class TaggedLogging def initialize(logger) @logger = logger - @tags = Hash.new { |h,k| h[k] = [] } end - def tagged(*new_tags) - tags = current_tags - new_tags = Array.wrap(new_tags).flatten.reject(&:blank?) - tags.concat new_tags - yield + def tagged(*tags) + new_tags = push_tags(*tags) + yield self ensure - new_tags.size.times { tags.pop } + pop_tags(new_tags.size) + end + + def push_tags(*tags) + tags.flatten.reject(&:blank?).tap do |new_tags| + current_tags.concat new_tags + end + end + + def pop_tags(size = 1) + current_tags.pop size + end + + def clear_tags! + current_tags.clear end def silence(temporary_level = Logger::ERROR, &block) @@ -46,7 +57,7 @@ module ActiveSupport end def flush - @tags.delete(Thread.current) + clear_tags! @logger.flush if @logger.respond_to?(:flush) end @@ -54,17 +65,16 @@ module ActiveSupport @logger.send(method, *args) end - protected - - def tags_text - tags = current_tags - if tags.any? - tags.collect { |tag| "[#{tag}]" }.join(" ") + " " + private + def tags_text + tags = current_tags + if tags.any? + tags.collect { |tag| "[#{tag}] " }.join + end end - end - def current_tags - @tags[Thread.current] - end + def current_tags + Thread.current[:activesupport_tagged_logging_tags] ||= [] + end end end diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index d3adf671a0..a3c378f057 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -177,7 +177,11 @@ module ActiveSupport # Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and +formatted_offset+, respectively, before passing to # Time#strftime, so that zone information is correct def strftime(format) - format = format.gsub('%Z', zone).gsub('%z', formatted_offset(false)) + format = format.gsub('%Z', zone). + gsub('%z', formatted_offset(false)). + gsub('%:z', formatted_offset(true)). + gsub('%::z', formatted_offset(true) + ":00") + time.strftime(format) end |