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 Apr 20, 2023
1 parent f36f8d8 commit f3b5fef
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,14 +216,18 @@ 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

def lograge_config
application.config.lograge
end

def deprecator
@deprecator ||= ActiveSupport::Deprecation.new('1.0', 'Lograge')
end
end
# rubocop:enable Metrics/ModuleLength

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 @@ -164,7 +164,7 @@ def current_user_id
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 f3b5fef

Please sign in to comment.