diff --git a/Changes.md b/Changes.md index 65029be27..bf4b8566f 100644 --- a/Changes.md +++ b/Changes.md @@ -5,6 +5,9 @@ HEAD --------- +- **FEATURE**: Sidekiq.logger has been enhanced so any `Rails.logger` + output in jobs now shows up in the Sidekiq console. Remove any logger + hacks in your initializer and see if it Just Works™ now. [#5021] - **FEATURE**: Add `Sidekiq::Job` alias for `Sidekiq::Worker`, to better reflect industry standard terminology. You can now do this: ```ruby diff --git a/lib/sidekiq/rails.rb b/lib/sidekiq/rails.rb index 5ac6b3dcb..33b7d4909 100644 --- a/lib/sidekiq/rails.rb +++ b/lib/sidekiq/rails.rb @@ -37,6 +37,17 @@ def inspect end end + initializer "sidekiq.rails_logger" do + Sidekiq.configure_server do |_| + # This is the integration code necessary so that if code uses `Rails.logger.info "Hello"`, + # it will appear in the Sidekiq console with all of the job context. See #5021 and + # https://github.com/rails/rails/blob/b5f2b550f69a99336482739000c58e4e04e033aa/railties/lib/rails/commands/server/server_command.rb#L82-L84 + unless ::ActiveSupport::Logger.logger_outputs_to?(::Rails.logger, STDOUT) + ::Rails.logger.extend(::ActiveSupport::Logger.broadcast(::Sidekiq.logger)) + end + end + end + # This hook happens after all initializers are run, just before returning # from config/environment.rb back to sidekiq/cli.rb. #