mirror of https://github.com/rails/rails
Do not overwrite AJ logger if it is supplied
Use conditional assignment within 'active_job.logger' initializer
This commit is contained in:
parent
82e33e44bf
commit
e03cc187f5
|
@ -15,7 +15,7 @@ module ActiveJob
|
|||
end
|
||||
|
||||
initializer "active_job.logger" do
|
||||
ActiveSupport.on_load(:active_job) { self.logger = ::Rails.logger }
|
||||
ActiveSupport.on_load(:active_job) { self.logger ||= ::Rails.logger }
|
||||
end
|
||||
|
||||
initializer "active_job.custom_serializers" do |app|
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "helper"
|
||||
require "active_support/testing/isolation"
|
||||
|
||||
class RailtieTest < ActiveSupport::TestCase
|
||||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
setup do
|
||||
require "rails"
|
||||
|
||||
rails_logger = Logger.new(nil)
|
||||
|
||||
@app ||= Class.new(::Rails::Application) do
|
||||
def self.name; "AJRailtieTestApp"; end
|
||||
|
||||
config.eager_load = false
|
||||
config.logger = rails_logger
|
||||
config.active_support.cache_format_version = 7.1
|
||||
end
|
||||
end
|
||||
|
||||
test "active_job.logger initializer does not overwrite the supplied logger" do
|
||||
custom_logger = Logger.new(nil)
|
||||
|
||||
@app.config.before_initialize do |app|
|
||||
ActiveSupport.on_load(:active_job) do
|
||||
self.logger = custom_logger
|
||||
end
|
||||
end
|
||||
|
||||
require "active_job/railtie"
|
||||
@app.initialize!
|
||||
|
||||
assert_same ActiveJob::Base.logger, custom_logger
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue