diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-09-08 23:53:37 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-09-08 23:53:37 +0200 |
commit | 3e55fd755ac9c1d1f84f8dadd42112e2ee592a3a (patch) | |
tree | 87e4545da06d77b6203e3daaa04c4dcd023e8370 | |
parent | 997acb9aadab4df57b5a4ce88ddce3ec9d5f5f45 (diff) | |
parent | 26f37f7c401d95acb582dbb1d820e2333f84f217 (diff) | |
download | rails-3e55fd755ac9c1d1f84f8dadd42112e2ee592a3a.tar.gz rails-3e55fd755ac9c1d1f84f8dadd42112e2ee592a3a.tar.bz2 rails-3e55fd755ac9c1d1f84f8dadd42112e2ee592a3a.zip |
Merge pull request #21518 from codebaker95/activejob_logging_fix
Properly log nested parameters to Active Job
-rw-r--r-- | activejob/lib/active_job/logging.rb | 16 | ||||
-rw-r--r-- | activejob/test/cases/logging_test.rb | 8 |
2 files changed, 23 insertions, 1 deletions
diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb index 54774db601..d72e1bdfce 100644 --- a/activejob/lib/active_job/logging.rb +++ b/activejob/lib/active_job/logging.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/hash/transform_values' require 'active_support/core_ext/string/filters' require 'active_support/tagged_logging' require 'active_support/logger' @@ -87,12 +88,25 @@ module ActiveJob def args_info(job) if job.arguments.any? ' with arguments: ' + - job.arguments.map { |arg| arg.try(:to_global_id).try(:to_s) || arg.inspect }.join(', ') + job.arguments.map { |arg| format(arg).inspect }.join(', ') else '' end end + def format(arg) + case arg + when Hash + arg.transform_values { |value| format(value) } + when Array + arg.map { |value| format(value) } + when GlobalID::Identification + arg.to_global_id rescue arg + else + arg + end + end + def scheduled_at(event) Time.at(event.payload[:job].scheduled_at).utc end diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index b18be553ec..820e9112de 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -74,6 +74,14 @@ class LoggingTest < ActiveSupport::TestCase assert_match(%r{Performing.*gid://aj/Person/123}, @logger.messages) end + def test_globalid_nested_parameter_logging + person = Person.new(123) + LoggingJob.perform_later(person: person) + assert_match(%r{Enqueued.*gid://aj/Person/123}, @logger.messages) + assert_match(%r{Dummy, here is it: .*#<Person:.*>}, @logger.messages) + assert_match(%r{Performing.*gid://aj/Person/123}, @logger.messages) + end + def test_enqueue_job_logging HelloJob.perform_later "Cristian" assert_match(/Enqueued HelloJob \(Job ID: .*?\) to .*?:.*Cristian/, @logger.messages) |