Do not overwrite AJ logger if it is supplied

Use conditional assignment within 'active_job.logger' initializer
This commit is contained in:
Aerdayne 2023-11-24 23:06:52 +01:00
parent 82e33e44bf
commit e03cc187f5
2 changed files with 38 additions and 1 deletions

View File

@ -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|

View File

@ -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