From bc5ef25fda105f2669a1a5314b3994104485baec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Thu, 20 Apr 2023 11:34:14 +0200 Subject: [PATCH] Use a dedicated ActiveSupport::Deprecation 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. --- lib/lograge.rb | 6 +++++- lib/lograge/railtie.rb | 4 ++++ spec/lograge_spec.rb | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/lograge.rb b/lib/lograge.rb index cfa1a5bc..7ac247ac 100644 --- a/lib/lograge.rb +++ b/lib/lograge.rb @@ -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 @@ -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) diff --git a/lib/lograge/railtie.rb b/lib/lograge/railtie.rb index 69cf5f98..bbfaa176 100644 --- a/lib/lograge/railtie.rb +++ b/lib/lograge/railtie.rb @@ -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 diff --git a/spec/lograge_spec.rb b/spec/lograge_spec.rb index f97f4a72..68b1e2e0 100644 --- a/spec/lograge_spec.rb +++ b/spec/lograge_spec.rb @@ -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