Skip to content

Commit

Permalink
Merge pull request #11872 from AvnerCohen/log_namespace
Browse files Browse the repository at this point in the history
When testing cache issues, it is useful to log the actual key, including namespace
  • Loading branch information
sgrif committed Oct 30, 2015
2 parents e038975 + f654d65 commit 6c61ae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/cache.rb
Expand Up @@ -538,7 +538,7 @@ def namespaced_key(key, options)
end

def instrument(operation, key, options = nil)
log { "Cache #{operation}: #{key}#{options.blank? ? "" : " (#{options.inspect})"}" }
log { "Cache #{operation}: #{namespaced_key(key, options)}#{options.blank? ? "" : " (#{options.inspect})"}" }

payload = { :key => key }
payload.merge!(options) if options.is_a?(Hash)
Expand Down
13 changes: 13 additions & 0 deletions activesupport/test/caching_test.rb
Expand Up @@ -1086,6 +1086,19 @@ def test_logging
assert @buffer.string.present?
end

def test_log_with_string_namespace
@cache.fetch('foo', {namespace: 'string_namespace'}) { 'bar' }
assert_match %r{string_namespace:foo}, @buffer.string
end

def test_log_with_proc_namespace
proc = Proc.new do
"proc_namespace"
end
@cache.fetch('foo', {:namespace => proc}) { 'bar' }
assert_match %r{proc_namespace:foo}, @buffer.string
end

def test_mute_logging
@cache.mute { @cache.fetch('foo') { 'bar' } }
assert @buffer.string.blank?
Expand Down

0 comments on commit 6c61ae8

Please sign in to comment.