Skip to content

Commit

Permalink
Use a dedicated ActiveSupport::Deprecation
Browse files Browse the repository at this point in the history
Rails 7.1 will deprecate using the singleton ActiveSupport::Deprecation
instance (rails/rails#47354). This defines one for the gem and uses it.

It's also added to the application's set of deprecators, allowing it to
be configured along all the other deprecators.
  • Loading branch information
etiennebarrie committed Sep 27, 2023
1 parent f6ca5bc commit bc5ef25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/lograge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def support_deprecated_config

legacy_log_format = lograge_config.log_format
warning = 'config.lograge.log_format is deprecated. Use config.lograge.formatter instead.'
ActiveSupport::Deprecation.warn(warning, caller)
deprecator.warn(warning, caller)
legacy_log_format = :key_value if legacy_log_format == :lograge
lograge_config.formatter = "Lograge::Formatters::#{legacy_log_format.to_s.classify}".constantize.new
end
Expand All @@ -225,6 +225,10 @@ def lograge_config
application.config.lograge
end

def deprecator
@deprecator ||= ActiveSupport::Deprecation.new('1.0', 'Lograge')
end

if ::ActiveSupport::VERSION::MAJOR >= 8 ||
(::ActiveSupport::VERSION::MAJOR >= 7 && ::ActiveSupport::VERSION::MINOR >= 1)
def notification_listeners_for(name)
Expand Down
4 changes: 4 additions & 0 deletions lib/lograge/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Railtie < Rails::Railtie
config.lograge = Lograge::OrderedOptions.new
config.lograge.enabled = false

initializer :deprecator do |app|
app.deprecators[:lograge] = Lograge.deprecator if app.respond_to?(:deprecators)
end

config.after_initialize do |app|
Lograge.setup(app) if app.config.lograge.enabled
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lograge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def logger; end
config.lograge.log_format = format
end)
end
before { ActiveSupport::Deprecation.silence { Lograge.setup(app_config) } }
before { Lograge.deprecator.silence { Lograge.setup(app_config) } }
subject { Lograge.formatter }

context ':cee' do
Expand Down

0 comments on commit bc5ef25

Please sign in to comment.