Skip to content

Commit d2fdf7e

Browse files
morgothrosa
authored andcommitted
Fix setting Rails logger by default.
In addition, introduce load hooks for `:solid_queue`. This solution is borrowed from the GoodJob codebase.
1 parent 85ec732 commit d2fdf7e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/solid_queue.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
module SolidQueue
2121
extend self
2222

23-
mattr_accessor :logger, default: ActiveSupport::Logger.new($stdout)
23+
DEFAULT_LOGGER = ActiveSupport::Logger.new($stdout)
24+
25+
mattr_accessor :logger, default: DEFAULT_LOGGER
2426
mattr_accessor :app_executor, :on_thread_error, :connects_to
2527

2628
mattr_accessor :use_skip_locked, default: true
@@ -56,4 +58,6 @@ def preserve_finished_jobs?
5658
def instrument(channel, **options, &block)
5759
ActiveSupport::Notifications.instrument("#{channel}.solid_queue", **options, &block)
5860
end
61+
62+
ActiveSupport.run_load_hooks(:solid_queue, self)
5963
end

lib/solid_queue/engine.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class Engine < ::Rails::Engine
2424
SolidQueue.on_thread_error = config.solid_queue.on_thread_error
2525
end
2626

27-
initializer "solid_queue.logger" do |app|
27+
initializer "solid_queue.logger" do
2828
ActiveSupport.on_load(:solid_queue) do
29-
self.logger ||= app.logger
29+
self.logger = ::Rails.logger if logger == SolidQueue::DEFAULT_LOGGER
3030
end
3131

3232
SolidQueue::LogSubscriber.attach_to :solid_queue

0 commit comments

Comments
 (0)