mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Only filter GIDable objects; remove cosmetic changes
This commit is contained in:
parent
802630378e
commit
25c8ea264e
2 changed files with 14 additions and 16 deletions
|
@ -6,8 +6,6 @@ module ActiveJob
|
||||||
module Logging #:nodoc:
|
module Logging #:nodoc:
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
FILTERED = '[FILTERED]'.freeze
|
|
||||||
|
|
||||||
included do
|
included do
|
||||||
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
||||||
|
|
||||||
|
@ -86,20 +84,20 @@ module ActiveJob
|
||||||
event.payload[:adapter].name.demodulize.remove('Adapter') + "(#{event.payload[:job].queue_name})"
|
event.payload[:adapter].name.demodulize.remove('Adapter') + "(#{event.payload[:job].queue_name})"
|
||||||
end
|
end
|
||||||
|
|
||||||
def global_id_or_filtered(argument)
|
def global_id_or_inspected(argument)
|
||||||
if argument.is_a?(GlobalID::Identification)
|
if argument.is_a?(GlobalID::Identification)
|
||||||
argument.to_global_id.to_s
|
argument.to_global_id.to_s
|
||||||
else
|
else
|
||||||
FILTERED
|
argument.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def args_info(job)
|
def args_info(job)
|
||||||
if job.arguments.any?
|
if job.arguments.any?
|
||||||
' with arguments: ' +
|
' with arguments: ' +
|
||||||
job.arguments.map { |arg| global_id_or_filtered(arg) }.join(', ')
|
job.arguments.map { |arg| global_id_or_inspected(arg) }.join(', ')
|
||||||
else
|
else
|
||||||
""
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,24 +42,24 @@ class AdapterTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
|
|
||||||
def test_uses_active_job_as_tag
|
def test_uses_active_job_as_tag
|
||||||
HelloJob.perform_later nil
|
HelloJob.perform_later "Cristian"
|
||||||
assert_match(/\[ActiveJob\]/, @logger.messages)
|
assert_match(/\[ActiveJob\]/, @logger.messages)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uses_job_name_as_tag
|
def test_uses_job_name_as_tag
|
||||||
LoggingJob.perform_later nil
|
LoggingJob.perform_later "Dummy"
|
||||||
assert_match(/\[LoggingJob\]/, @logger.messages)
|
assert_match(/\[LoggingJob\]/, @logger.messages)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uses_job_id_as_tag
|
def test_uses_job_id_as_tag
|
||||||
LoggingJob.perform_later nil
|
LoggingJob.perform_later "Dummy"
|
||||||
assert_match(/\[LOGGING-JOB-ID\]/, @logger.messages)
|
assert_match(/\[LOGGING-JOB-ID\]/, @logger.messages)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_logs_correct_queue_name
|
def test_logs_correct_queue_name
|
||||||
original_queue_name = LoggingJob.queue_name
|
original_queue_name = LoggingJob.queue_name
|
||||||
LoggingJob.queue_as :php_jobs
|
LoggingJob.queue_as :php_jobs
|
||||||
LoggingJob.perform_later nil
|
LoggingJob.perform_later("Dummy")
|
||||||
assert_match(/to .*?\(php_jobs\).*/, @logger.messages)
|
assert_match(/to .*?\(php_jobs\).*/, @logger.messages)
|
||||||
ensure
|
ensure
|
||||||
LoggingJob.queue_name = original_queue_name
|
LoggingJob.queue_name = original_queue_name
|
||||||
|
@ -75,12 +75,12 @@ class AdapterTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_enqueue_job_logging
|
def test_enqueue_job_logging
|
||||||
HelloJob.perform_later "Cristian"
|
HelloJob.perform_later "Cristian"
|
||||||
assert_match(/Enqueued HelloJob \(Job ID: .*?\) to .*?:.*\[FILTERED\]/, @logger.messages)
|
assert_match(/Enqueued HelloJob \(Job ID: .*?\) to .*?:.*Cristian/, @logger.messages)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_perform_job_logging
|
def test_perform_job_logging
|
||||||
LoggingJob.perform_later "Dummy"
|
LoggingJob.perform_later "Dummy"
|
||||||
assert_match(/Performing LoggingJob from .*? with arguments:.*\[FILTERED\]/, @logger.messages)
|
assert_match(/Performing LoggingJob from .*? with arguments:.*Dummy/, @logger.messages)
|
||||||
assert_match(/Dummy, here is it: Dummy/, @logger.messages)
|
assert_match(/Dummy, here is it: Dummy/, @logger.messages)
|
||||||
assert_match(/Performed LoggingJob from .*? in .*ms/, @logger.messages)
|
assert_match(/Performed LoggingJob from .*? in .*ms/, @logger.messages)
|
||||||
end
|
end
|
||||||
|
@ -90,8 +90,8 @@ class AdapterTest < ActiveSupport::TestCase
|
||||||
assert_match(/\[LoggingJob\] \[.*?\]/, @logger.messages)
|
assert_match(/\[LoggingJob\] \[.*?\]/, @logger.messages)
|
||||||
assert_match(/\[ActiveJob\] Enqueued NestedJob \(Job ID: .*\) to/, @logger.messages)
|
assert_match(/\[ActiveJob\] Enqueued NestedJob \(Job ID: .*\) to/, @logger.messages)
|
||||||
assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Performing NestedJob from/, @logger.messages)
|
assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Performing NestedJob from/, @logger.messages)
|
||||||
assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Enqueued LoggingJob \(Job ID: .*?\) to .* with arguments: \[FILTERED\]/, @logger.messages)
|
assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Enqueued LoggingJob \(Job ID: .*?\) to .* with arguments: "NestedJob"/, @logger.messages)
|
||||||
assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Performing LoggingJob from .* with arguments: \[FILTERED\]/, @logger.messages)
|
assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Performing LoggingJob from .* with arguments: "NestedJob"/, @logger.messages)
|
||||||
assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Dummy, here is it: NestedJob/, @logger.messages)
|
assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Dummy, here is it: NestedJob/, @logger.messages)
|
||||||
assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Performed LoggingJob from .* in/, @logger.messages)
|
assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Performed LoggingJob from .* in/, @logger.messages)
|
||||||
assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Performed NestedJob from .* in/, @logger.messages)
|
assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Performed NestedJob from .* in/, @logger.messages)
|
||||||
|
@ -99,14 +99,14 @@ class AdapterTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_enqueue_at_job_logging
|
def test_enqueue_at_job_logging
|
||||||
HelloJob.set(wait_until: 24.hours.from_now).perform_later "Cristian"
|
HelloJob.set(wait_until: 24.hours.from_now).perform_later "Cristian"
|
||||||
assert_match(/Enqueued HelloJob \(Job ID: .*\) to .*? at.*\[FILTERED\]/, @logger.messages)
|
assert_match(/Enqueued HelloJob \(Job ID: .*\) to .*? at.*Cristian/, @logger.messages)
|
||||||
rescue NotImplementedError
|
rescue NotImplementedError
|
||||||
skip
|
skip
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enqueue_in_job_logging
|
def test_enqueue_in_job_logging
|
||||||
HelloJob.set(wait: 2.seconds).perform_later "Cristian"
|
HelloJob.set(wait: 2.seconds).perform_later "Cristian"
|
||||||
assert_match(/Enqueued HelloJob \(Job ID: .*\) to .*? at.*\[FILTERED\]/, @logger.messages)
|
assert_match(/Enqueued HelloJob \(Job ID: .*\) to .*? at.*Cristian/, @logger.messages)
|
||||||
rescue NotImplementedError
|
rescue NotImplementedError
|
||||||
skip
|
skip
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue