Support Sidekiq v7
supairish opened this issue · 2 comments
Hello!
Environment
- Ruby Version.
3.1.2 - Rails Version.
7.0.3 - Semantic Logger Version.
4.11.0 - Rails Semantic Logger Version.
4.10.0 - Other Application/framework names and versions (e.g. Puma, etc.).
Sidekiq 7.0 - Full Stack Trace, if an exception is being raised.
See below
Expected Behavior
I should be able to override the default Sidekiq logger with a semantic logger
- Provide a standalone Ruby script or a link to an example repository that helps reproduce the issue.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "rails", "~> 7.0.0"
gem "amazing_print"
gem 'rails_semantic_logger', '~> 4.10.0'
gem 'sidekiq', '7.0'
end
require "rack/test"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_key_base = "secret_key_base"
# Replace the Sidekiq logger
Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq)
routes.draw do
get "/" => "test#index"
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render plain: "Home"
end
end
require "minitest/autorun"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get "/"
assert last_response.ok?
end
private
def app
Rails.application
end
end
Actual Behavior
- Describe or show the actual behavior.
If you upgrade from Sidekiq 6.x to 7.x. Attempting to boot app will raise exception due to Sidekiq removing the global module setter "logger= "
Not 100% sure but it appears options like this will now have to go through a config block setup
Comment found here
sidekiq/sidekiq@v6.5.7...v7.0.0#diff-6985e251e1b3fe0ce1f47369a1ede593aab9b27757ac7ff6e16591bc0318b034R86
Logger moved to Sidekiq::Config
sidekiq/sidekiq@v6.5.7...v7.0.0#diff-6605d43f981434252c6bd19fecf05464aef2436da1225630105f7ff2c0265ab1R245
- Provide text or screen capture showing the behavior.
NoMethodError:
undefined method `logger=' for Sidekiq:Module
Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq)
^^^^^^^^^^^^^^^
Did you mean? logger
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/rails_semantic_logger-4.10.0/lib/rails_semantic_logger/engine.rb:113:in `block in <class:Engine>'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.4/lib/active_support/lazy_load_hooks.rb:92:in `block in execute_hook'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.4/lib/active_support/lazy_load_hooks.rb:85:in `with_execution_control'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.4/lib/active_support/lazy_load_hooks.rb:90:in `execute_hook'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.4/lib/active_support/lazy_load_hooks.rb:76:in `block in run_load_hooks'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.4/lib/active_support/lazy_load_hooks.rb:75:in `each'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.4/lib/active_support/lazy_load_hooks.rb:75:in `run_load_hooks'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4/lib/rails/application/bootstrap.rb:92:in `block in <module:Bootstrap>'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `instance_exec'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `run'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4/lib/rails/initializable.rb:61:in `block in run_initializers'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4/lib/rails/initializable.rb:60:in `run_initializers'
# /Users/supairish/.rvm/gems/ruby-3.1.2/gems/railties-7.0.4/lib/rails/application.rb:372:in `initialize!'
# ./config/environment.rb:7:in `<top (required)>'
This commit will disable the automatic logger replacement, since Sidekiq 7 is not backward compatible. a64c480
Going to leave the issue open to determine we need to move replacing Sidekiq logging into a documentation change, or if there is some way to automatically replace the logger as it does today for Sidekiq v6.
Published rails_semantic_logger (4.11.0) to check for Sidekiq upto v6.
This discussion covers how to configure Sidekiq logging with v7 now:
reidmorrison/semantic_logger#246