diff options
author | wycats <wycats@gmail.com> | 2010-06-29 12:18:17 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-06-29 12:20:15 -0700 |
commit | d4c7d3fd94e5a885a6366eaeb3b908bb58ffd4db (patch) | |
tree | 83eb729393ddffc4fb06f6c49c96c9bf758220e6 /activesupport/lib/active_support/deprecation | |
parent | 21957b72ea394c679d9b17e75b570cc99596322d (diff) | |
download | rails-d4c7d3fd94e5a885a6366eaeb3b908bb58ffd4db.tar.gz rails-d4c7d3fd94e5a885a6366eaeb3b908bb58ffd4db.tar.bz2 rails-d4c7d3fd94e5a885a6366eaeb3b908bb58ffd4db.zip |
Create a deprecation behavior that triggers a notification for deprecation notices, and make the behaviors independent of the environment names.
* In Rails 2.3 apps being upgraded, you will need to add the deprecation
configuration to each of your environments. Failing to do so will
result in the same behavior as Rails 2.3, but with an outputted warning
to provide information on how to set up the setting.
* New Rails 3 applications generate the setting
* The notification style will send deprecation notices using
ActiveSupport::Notifications. Third-party tools can listen in to
these notifications to provide a streamlined view of the
deprecation notices occurring in your app.
* The payload in the notification is the deprecation warning itself
as well as the callstack from the point that triggered the
notification.
Diffstat (limited to 'activesupport/lib/active_support/deprecation')
-rw-r--r-- | activesupport/lib/active_support/deprecation/behaviors.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 578c025fcf..feb1508586 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -1,28 +1,27 @@ +require "active_support/notifications" + module ActiveSupport module Deprecation class << self - # Behavior is a block that takes a message argument. - attr_writer :behavior - # Whether to print a backtrace along with the warning. attr_accessor :debug def behavior - @behavior ||= default_behavior + @behavior ||= DEFAULT_BEHAVIORS[:stderr] end - def default_behavior - Deprecation::DEFAULT_BEHAVIORS[defined?(Rails.env) ? Rails.env.to_s : 'test'] + def behavior=(behavior) + @behavior = DEFAULT_BEHAVIORS[behavior] || behavior end end - # Default warning behaviors per Rails.env. Ignored in production. + # Default warning behaviors per Rails.env. DEFAULT_BEHAVIORS = { - 'test' => Proc.new { |message, callstack| + :stderr => Proc.new { |message, callstack| $stderr.puts(message) $stderr.puts callstack.join("\n ") if debug }, - 'development' => Proc.new { |message, callstack| + :log => Proc.new { |message, callstack| logger = if defined?(Rails) && Rails.logger Rails.logger @@ -32,6 +31,10 @@ module ActiveSupport end logger.warn message logger.debug callstack.join("\n ") if debug + }, + :notify => Proc.new { |message, callstack| + ActiveSupport::Notifications.instrument("deprecation.rails", + :message => message, :callstack => callstack) } } end |