Skip to content

Commit

Permalink
Integrate Sidekiq.logger into Rails.logger, closes #5021
Browse files Browse the repository at this point in the history
Any use of Rails.logger in jobs will now go to the Sidekiq logger.
  • Loading branch information
mperham committed Oct 12, 2021
1 parent 717e7fd commit 90535ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/sidekiq/rails.rb
Expand Up @@ -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.
#
Expand Down

0 comments on commit 90535ab

Please sign in to comment.