mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix jobs overriding AJ::Base#logger
This commit is contained in:
parent
30dd8b2cb0
commit
be491ecec2
3 changed files with 16 additions and 2 deletions
|
@ -41,7 +41,7 @@ module ActiveJob
|
|||
def tag_logger(*tags)
|
||||
if logger.respond_to?(:tagged)
|
||||
tags.unshift "ActiveJob" unless logger_tagged_by_active_job?
|
||||
ActiveJob::Base.logger.tagged(*tags){ yield }
|
||||
logger.tagged(*tags){ yield }
|
||||
else
|
||||
yield
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ require "active_support/log_subscriber/test_helper"
|
|||
require 'active_support/core_ext/numeric/time'
|
||||
require 'jobs/hello_job'
|
||||
require 'jobs/logging_job'
|
||||
require 'jobs/overridden_logging_job'
|
||||
require 'jobs/nested_job'
|
||||
require 'models/person'
|
||||
|
||||
|
@ -41,7 +42,6 @@ class LoggingTest < ActiveSupport::TestCase
|
|||
ActiveJob::Base.logger = logger
|
||||
end
|
||||
|
||||
|
||||
def test_uses_active_job_as_tag
|
||||
HelloJob.perform_later "Cristian"
|
||||
assert_match(/\[ActiveJob\]/, @logger.messages)
|
||||
|
@ -119,4 +119,9 @@ class LoggingTest < ActiveSupport::TestCase
|
|||
rescue NotImplementedError
|
||||
skip
|
||||
end
|
||||
|
||||
def test_for_tagged_logger_support_is_consistent
|
||||
set_logger ::Logger.new(nil)
|
||||
OverriddenLoggingJob.perform_later "Dummy"
|
||||
end
|
||||
end
|
||||
|
|
9
activejob/test/jobs/overridden_logging_job.rb
Normal file
9
activejob/test/jobs/overridden_logging_job.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class OverriddenLoggingJob < ActiveJob::Base
|
||||
def perform(dummy)
|
||||
logger.info "Dummy, here is it: #{dummy}"
|
||||
end
|
||||
|
||||
def logger
|
||||
@logger ||= ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(nil))
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue