Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename Rails::Subscriber to Rails::LogSubscriber

  • Loading branch information...
commit f0523f72b46db14e2f50c8347a8708734c650f84 1 parent 7cff54f
@sikachu sikachu authored josevalim committed
Showing with 233 additions and 233 deletions.
  1. +2 −2 actionmailer/lib/action_mailer/railtie.rb
  2. +1 −1  actionmailer/lib/action_mailer/railties/{subscriber.rb → log_subscriber.rb}
  3. +5 −5 actionmailer/test/{subscriber_test.rb → log_subscriber_test.rb}
  4. +2 −2 actionpack/lib/action_controller/railtie.rb
  5. +1 −1  actionpack/lib/action_controller/railties/{subscriber.rb → log_subscriber.rb}
  6. +2 −2 actionpack/lib/action_view/railtie.rb
  7. +1 −1  actionpack/lib/action_view/railties/{subscriber.rb → log_subscriber.rb}
  8. +8 −8 actionpack/test/activerecord/controller_runtime_test.rb
  9. +9 −9 actionpack/test/controller/{subscriber_test.rb → log_subscriber_test.rb}
  10. +6 −6 actionpack/test/template/{subscriber_test.rb → log_subscriber_test.rb}
  11. +1 −1  activerecord/lib/active_record/base.rb
  12. +2 −2 activerecord/lib/active_record/railtie.rb
  13. +1 −1  activerecord/lib/active_record/railties/{subscriber.rb → log_subscriber.rb}
  14. +5 −5 activerecord/test/cases/{subscriber_test.rb → log_subscriber_test.rb}
  15. +2 −2 activeresource/lib/active_resource/railtie.rb
  16. +1 −1  activeresource/lib/active_resource/railties/{subscriber.rb → log_subscriber.rb}
  17. +5 −5 activeresource/test/cases/{subscriber_test.rb → log_subscriber_test.rb}
  18. +2 −2 activesupport/lib/active_support/notifications.rb
  19. +5 −5 activesupport/lib/active_support/notifications/fanout.rb
  20. +3 −3 activesupport/test/notifications_test.rb
  21. +1 −1  railties/guides/source/3_0_release_notes.textile
  22. +1 −1  railties/lib/rails.rb
  23. +4 −4 railties/lib/rails/application/bootstrap.rb
  24. +18 −18 railties/lib/rails/{subscriber.rb → log_subscriber.rb}
  25. +16 −16 railties/lib/rails/{subscriber → log_subscriber}/test_helper.rb
  26. +3 −3 railties/lib/rails/rack/logger.rb
  27. +2 −2 railties/lib/rails/railtie.rb
  28. +1 −1  railties/test/application/initializers/notifications_test.rb
  29. +119 −0 railties/test/log_subscriber_test.rb
  30. +4 −4 railties/test/railties/railtie_test.rb
  31. +0 −119 railties/test/subscriber_test.rb
View
4 actionmailer/lib/action_mailer/railtie.rb
@@ -9,8 +9,8 @@ class Railtie < Rails::Railtie
ActionMailer::Base.send(:include, ActionController::UrlFor) if defined?(ActionController)
end
- require "action_mailer/railties/subscriber"
- subscriber ActionMailer::Railties::Subscriber.new
+ require "action_mailer/railties/log_subscriber"
+ log_subscriber ActionMailer::Railties::LogSubscriber.new
initializer "action_mailer.logger" do
ActionMailer::Base.logger ||= Rails.logger
View
2  .../lib/action_mailer/railties/subscriber.rb → .../action_mailer/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActionMailer
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def deliver(event)
recipients = Array(event.payload[:to]).join(', ')
info("\nSent mail to #{recipients} (%1.fms)" % event.duration)
View
10 actionmailer/test/subscriber_test.rb → actionmailer/test/log_subscriber_test.rb
@@ -1,10 +1,10 @@
require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_mailer/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "action_mailer/railties/log_subscriber"
-class AMSubscriberTest < ActionMailer::TestCase
- include Rails::Subscriber::TestHelper
- Rails::Subscriber.add(:action_mailer, ActionMailer::Railties::Subscriber.new)
+class AMLogSubscriberTest < ActionMailer::TestCase
+ include Rails::LogSubscriber::TestHelper
+ Rails::LogSubscriber.add(:action_mailer, ActionMailer::Railties::LogSubscriber.new)
class TestMailer < ActionMailer::Base
def basic
View
4 actionpack/lib/action_controller/railtie.rb
@@ -6,8 +6,8 @@ module ActionController
class Railtie < Rails::Railtie
railtie_name :action_controller
- require "action_controller/railties/subscriber"
- subscriber ActionController::Railties::Subscriber.new
+ require "action_controller/railties/log_subscriber"
+ log_subscriber ActionController::Railties::LogSubscriber.new
initializer "action_controller.logger" do
ActionController::Base.logger ||= Rails.logger
View
2  .../action_controller/railties/subscriber.rb → ...ion_controller/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActionController
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
INTERNAL_PARAMS = %w(controller action format _method only_path)
def start_processing(event)
View
4 actionpack/lib/action_view/railtie.rb
@@ -5,8 +5,8 @@ module ActionView
class Railtie < Rails::Railtie
railtie_name :action_view
- require "action_view/railties/subscriber"
- subscriber ActionView::Railties::Subscriber.new
+ require "action_view/railties/log_subscriber"
+ log_subscriber ActionView::Railties::LogSubscriber.new
initializer "action_view.cache_asset_timestamps" do |app|
unless app.config.cache_classes
View
2  ...ck/lib/action_view/railties/subscriber.rb → ...ib/action_view/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActionView
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def render_template(event)
message = "Rendered #{from_rails_root(event.payload[:identifier])}"
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
View
16 actionpack/test/activerecord/controller_runtime_test.rb
@@ -1,30 +1,30 @@
require 'active_record_unit'
require 'active_record/railties/controller_runtime'
require 'fixtures/project'
-require 'rails/subscriber/test_helper'
-require 'action_controller/railties/subscriber'
+require 'rails/log_subscriber/test_helper'
+require 'action_controller/railties/log_subscriber'
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
-class ControllerRuntimeSubscriberTest < ActionController::TestCase
- class SubscriberController < ActionController::Base
+class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
+ class LogSubscriberController < ActionController::Base
def show
render :inline => "<%= Project.all %>"
end
end
- include Rails::Subscriber::TestHelper
- tests SubscriberController
+ include Rails::LogSubscriber::TestHelper
+ tests LogSubscriberController
def setup
@old_logger = ActionController::Base.logger
- Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
+ Rails::LogSubscriber.add(:action_controller, ActionController::Railties::LogSubscriber.new)
super
end
def teardown
super
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
ActionController::Base.logger = @old_logger
end
View
18 ...onpack/test/controller/subscriber_test.rb → ...ck/test/controller/log_subscriber_test.rb
@@ -1,9 +1,9 @@
require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_controller/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "action_controller/railties/log_subscriber"
module Another
- class SubscribersController < ActionController::Base
+ class LogSubscribersController < ActionController::Base
def show
render :nothing => true
end
@@ -35,9 +35,9 @@ def with_page_cache
end
end
-class ACSubscriberTest < ActionController::TestCase
- tests Another::SubscribersController
- include Rails::Subscriber::TestHelper
+class ACLogSubscriberTest < ActionController::TestCase
+ tests Another::LogSubscribersController
+ include Rails::LogSubscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@@ -46,13 +46,13 @@ def setup
ActionController::Base.page_cache_directory = @cache_path
ActionController::Base.cache_store = :file_store, @cache_path
- Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
+ Rails::LogSubscriber.add(:action_controller, ActionController::Railties::LogSubscriber.new)
super
end
def teardown
super
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
FileUtils.rm_rf(@cache_path)
ActionController::Base.logger = @old_logger
end
@@ -65,7 +65,7 @@ def test_start_processing
get :show
wait
assert_equal 2, logs.size
- assert_equal "Processing by Another::SubscribersController#show as HTML", logs.first
+ assert_equal "Processing by Another::LogSubscribersController#show as HTML", logs.first
end
def test_process_action
View
12 actionpack/test/template/subscriber_test.rb → ...pack/test/template/log_subscriber_test.rb
@@ -1,22 +1,22 @@
require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_view/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "action_view/railties/log_subscriber"
require "controller/fake_models"
-class AVSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
+class AVLogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH))
- Rails::Subscriber.add(:action_view, ActionView::Railties::Subscriber.new)
+ Rails::LogSubscriber.add(:action_view, ActionView::Railties::LogSubscriber.new)
super
end
def teardown
super
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
ActionController::Base.logger = @old_logger
end
View
2  activerecord/lib/active_record/base.rb
@@ -552,7 +552,7 @@ class << self # Class methods
def colorize_logging(*args)
ActiveSupport::Deprecation.warn "ActiveRecord::Base.colorize_logging and " <<
"config.active_record.colorize_logging are deprecated. Please use " <<
- "Rails::Subscriber.colorize_logging or config.colorize_logging instead", caller
+ "Rails::LogSubscriber.colorize_logging or config.colorize_logging instead", caller
end
alias :colorize_logging= :colorize_logging
View
4 activerecord/lib/active_record/railtie.rb
@@ -20,8 +20,8 @@ class Railtie < Rails::Railtie
end
# TODO If we require the wrong file, the error never comes up.
- require "active_record/railties/subscriber"
- subscriber ActiveRecord::Railties::Subscriber.new
+ require "active_record/railties/log_subscriber"
+ log_subscriber ActiveRecord::Railties::LogSubscriber.new
initializer "active_record.initialize_timezone" do
ActiveRecord::Base.time_zone_aware_attributes = true
View
2  .../lib/active_record/railties/subscriber.rb → .../active_record/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActiveRecord
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def sql(event)
name = '%s (%.1fms)' % [event.payload[:name], event.duration]
sql = event.payload[:sql].squeeze(' ')
View
10 activerecord/test/cases/subscriber_test.rb → ...erecord/test/cases/log_subscriber_test.rb
@@ -1,11 +1,11 @@
require "cases/helper"
require "models/developer"
-require "rails/subscriber/test_helper"
-require "active_record/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "active_record/railties/log_subscriber"
-class SubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
- Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
+class LogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
+ Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
def setup
@old_logger = ActiveRecord::Base.logger
View
4 activeresource/lib/active_resource/railtie.rb
@@ -5,8 +5,8 @@ module ActiveResource
class Railtie < Rails::Railtie
railtie_name :active_resource
- require "active_resource/railties/subscriber"
- subscriber ActiveResource::Railties::Subscriber.new
+ require "active_resource/railties/log_subscriber"
+ log_subscriber ActiveResource::Railties::LogSubscriber.new
initializer "active_resource.set_configs" do |app|
app.config.active_resource.each do |k,v|
View
2  ...ib/active_resource/railties/subscriber.rb → ...ctive_resource/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActiveResource
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def request(event)
result = event.payload[:result]
info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}"
View
10 activeresource/test/cases/subscriber_test.rb → ...esource/test/cases/log_subscriber_test.rb
@@ -1,12 +1,12 @@
require "abstract_unit"
require "fixtures/person"
-require "rails/subscriber/test_helper"
-require "active_resource/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "active_resource/railties/log_subscriber"
require "active_support/core_ext/hash/conversions"
-class SubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
- Rails::Subscriber.add(:active_resource, ActiveResource::Railties::Subscriber.new)
+class LogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
+ Rails::LogSubscriber.add(:active_resource, ActiveResource::Railties::LogSubscriber.new)
def setup
@matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
View
4 activesupport/lib/active_support/notifications.rb
@@ -9,7 +9,7 @@ module ActiveSupport
# end
#
# You can consume those events and the information they provide by registering
- # a subscriber. For instance, let's store all instrumented events in an array:
+ # a log subscriber. For instance, let's store all instrumented events in an array:
#
# @events = []
#
@@ -35,7 +35,7 @@ module ActiveSupport
# end
#
# Notifications ships with a queue implementation that consumes and publish events
- # to subscribers in a thread. You can use any queue implementation you want.
+ # to log subscribers in a thread. You can use any queue implementation you want.
#
module Notifications
autoload :Instrumenter, 'active_support/notifications/instrumenter'
View
10 activesupport/lib/active_support/notifications/fanout.rb
@@ -1,10 +1,10 @@
module ActiveSupport
module Notifications
# This is a default queue implementation that ships with Notifications. It
- # just pushes events to all registered subscribers.
+ # just pushes events to all registered log subscribers.
class Fanout
def initialize
- @subscribers = []
+ @log_subscribers = []
end
def bind(pattern)
@@ -12,11 +12,11 @@ def bind(pattern)
end
def subscribe(pattern = nil, &block)
- @subscribers << Subscriber.new(pattern, &block)
+ @log_subscribers << LogSubscriber.new(pattern, &block)
end
def publish(*args)
- @subscribers.each { |s| s.publish(*args) }
+ @log_subscribers.each { |s| s.publish(*args) }
end
# This is a sync queue, so there is not waiting.
@@ -41,7 +41,7 @@ def subscribe(&block)
end
end
- class Subscriber #:nodoc:
+ class LogSubscriber #:nodoc:
def initialize(pattern, &block)
@pattern = pattern
@block = block
View
6 activesupport/test/notifications_test.rb
@@ -26,7 +26,7 @@ def test_events_are_published_to_a_listener
assert_equal [[:foo]], @events
end
- def test_subscriber_with_pattern
+ def test_log_subscriber_with_pattern
events = []
@notifier.subscribe('1') { |*args| events << args }
@@ -38,7 +38,7 @@ def test_subscriber_with_pattern
assert_equal [['1'], ['1.a']], events
end
- def test_subscriber_with_pattern_as_regexp
+ def test_log_subscriber_with_pattern_as_regexp
events = []
@notifier.subscribe(/\d/) { |*args| events << args }
@@ -50,7 +50,7 @@ def test_subscriber_with_pattern_as_regexp
assert_equal [['1'], ['a.1'], ['1.a']], events
end
- def test_multiple_subscribers
+ def test_multiple_log_subscribers
@another = []
@notifier.subscribe { |*args| @another << args }
@notifier.publish :foo
View
2  railties/guides/source/3_0_release_notes.textile
@@ -435,7 +435,7 @@ As well as the following deprecations:
* I18n error messages for ActiveRecord should be changed from :en.activerecord.errors.template to <tt>:en.errors.template</tt>.
* <tt>model.errors.on</tt> is deprecated in favour of <tt>model.errors[]</tt>
* validates_presence_of => validates... :presence => true
-* <tt>ActiveRecord::Base.colorize_logging</tt> and <tt>config.active_record.colorize_logging</tt> are deprecated in favour of <tt>Rails::Subscriber.colorize_logging</tt> or <tt>config.colorize_logging</tt>
+* <tt>ActiveRecord::Base.colorize_logging</tt> and <tt>config.active_record.colorize_logging</tt> are deprecated in favour of <tt>Rails::LogSubscriber.colorize_logging</tt> or <tt>config.colorize_logging</tt>
NOTE: While an implementation of State Machine has been in Active Record edge for some months now, it has been removed from the Rails 3.0 release.
View
2  railties/lib/rails.rb
@@ -7,7 +7,7 @@
require 'rails/application'
require 'rails/version'
require 'rails/deprecation'
-require 'rails/subscriber'
+require 'rails/log_subscriber'
require 'rails/ruby_version_check'
require 'active_support/railtie'
View
8 railties/lib/rails/application/bootstrap.rb
@@ -49,17 +49,17 @@ module Bootstrap
end
end
- # Initialize rails subscriber on top of notifications.
- initializer :initialize_subscriber do
+ # Initialize rails log subscriber on top of notifications.
+ initializer :initialize_log_subscriber do
require 'active_support/notifications'
if config.colorize_logging == false
- Rails::Subscriber.colorize_logging = false
+ Rails::LogSubscriber.colorize_logging = false
config.generators.colorize_logging = false
end
ActiveSupport::Notifications.subscribe do |*args|
- Rails::Subscriber.dispatch(args)
+ Rails::LogSubscriber.dispatch(args)
end
end
View
36 railties/lib/rails/subscriber.rb → railties/lib/rails/log_subscriber.rb
@@ -2,15 +2,15 @@
require 'active_support/notifications'
module Rails
- # Rails::Subscriber is an object set to consume ActiveSupport::Notifications
- # on initialization with solely purpose of logging. The subscriber dispatches
+ # Rails::LogSubscriber is an object set to consume ActiveSupport::Notifications
+ # on initialization with solely purpose of logging. The log subscriber dispatches
# notifications to a regirested object based on its given namespace.
#
- # An example would be ActiveRecord subscriber responsible for logging queries:
+ # An example would be ActiveRecord log subscriber responsible for logging queries:
#
# module ActiveRecord
# class Railtie
- # class Subscriber < Rails::Subscriber
+ # class LogSubscriber < Rails::LogSubscriber
# def sql(event)
# "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
# end
@@ -20,19 +20,19 @@ module Rails
#
# It's finally registed as:
#
- # Rails::Subscriber.add :active_record, ActiveRecord::Railtie::Subscriber.new
+ # Rails::LogSubscriber.add :active_record, ActiveRecord::Railtie::LogSubscriber.new
#
- # So whenever a "active_record.sql" notification arrive to Rails::Subscriber,
+ # So whenever a "active_record.sql" notification arrive to Rails::LogSubscriber,
# it will properly dispatch the event (ActiveSupport::Notifications::Event) to
# the sql method.
#
- # This is useful because it avoids spanning several subscribers just for logging
+ # This is useful because it avoids spanning several log subscribers just for logging
# purposes(which slows down the main thread). Besides of providing a centralized
# facility on top of Rails.logger.
#
- # Subscriber also has some helpers to deal with logging and automatically flushes
+ # Log subscriber also has some helpers to deal with logging and automatically flushes
# all logs when the request finishes (via action_dispatch.callback notification).
- class Subscriber
+ class LogSubscriber
mattr_accessor :colorize_logging
self.colorize_logging = true
@@ -50,30 +50,30 @@ class Subscriber
CYAN = "\e[36m"
WHITE = "\e[37m"
- def self.add(namespace, subscriber)
- subscribers[namespace.to_sym] = subscriber
+ def self.add(namespace, log_subscriber)
+ log_subscribers[namespace.to_sym] = log_subscriber
end
- def self.subscribers
- @subscribers ||= {}
+ def self.log_subscribers
+ @log_subscribers ||= {}
end
def self.dispatch(args)
namespace, name = args[0].split(".")
- subscriber = subscribers[namespace.to_sym]
+ log_subscriber = log_subscribers[namespace.to_sym]
- if subscriber.respond_to?(name) && subscriber.logger
+ if log_subscriber.respond_to?(name) && log_subscriber.logger
begin
- subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
+ log_subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
rescue Exception => e
Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
end
end
end
- # Flush all subscribers' logger.
+ # Flush all log_subscribers' logger.
def self.flush_all!
- loggers = subscribers.values.map(&:logger)
+ loggers = log_subscribers.values.map(&:logger)
loggers.uniq!
loggers.each { |l| l.flush if l.respond_to?(:flush) }
end
View
32 railties/lib/rails/subscriber/test_helper.rb → ...s/lib/rails/log_subscriber/test_helper.rb
@@ -1,13 +1,13 @@
-require 'rails/subscriber'
+require 'rails/log_subscriber'
module Rails
- class Subscriber
- # Provides some helpers to deal with testing subscribers by setting up
+ class LogSubscriber
+ # Provides some helpers to deal with testing log subscribers by setting up
# notifications. Take for instance ActiveRecord subscriber tests:
#
- # class SyncSubscriberTest < ActiveSupport::TestCase
- # include Rails::Subscriber::TestHelper
- # Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
+ # class SyncLogSubscriberTest < ActiveSupport::TestCase
+ # include Rails::LogSubscriber::TestHelper
+ # Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
#
# def test_basic_query_logging
# Developer.all
@@ -17,18 +17,18 @@ class Subscriber
# assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last
# end
#
- # class SyncSubscriberTest < ActiveSupport::TestCase
- # include Rails::Subscriber::SyncTestHelper
- # include SubscriberTest
+ # class SyncLogSubscriberTest < ActiveSupport::TestCase
+ # include Rails::LogSubscriber::SyncTestHelper
+ # include LogSubscriberTest
# end
#
- # class AsyncSubscriberTest < ActiveSupport::TestCase
- # include Rails::Subscriber::AsyncTestHelper
- # include SubscriberTest
+ # class AsyncLogSubscriberTest < ActiveSupport::TestCase
+ # include Rails::LogSubscriber::AsyncTestHelper
+ # include LogSubscriberTest
# end
# end
#
- # All you need to do is to ensure that your subscriber is added to Rails::Subscriber,
+ # All you need to do is to ensure that your log subscriber is added to Rails::Subscriber,
# as in the second line of the code above. The test helpers is reponsible for setting
# up the queue, subscriptions and turning colors in logs off.
#
@@ -42,8 +42,8 @@ def setup
@logger = MockLogger.new
@notifier = ActiveSupport::Notifications::Notifier.new(queue)
- Rails::Subscriber.colorize_logging = false
- @notifier.subscribe { |*args| Rails::Subscriber.dispatch(args) }
+ Rails::LogSubscriber.colorize_logging = false
+ @notifier.subscribe { |*args| Rails::LogSubscriber.dispatch(args) }
set_logger(@logger)
ActiveSupport::Notifications.notifier = @notifier
@@ -80,7 +80,7 @@ def wait
@notifier.wait
end
- # Overwrite if you use another logger in your subscriber:
+ # Overwrite if you use another logger in your log subscriber:
#
# def logger
# ActiveRecord::Base.logger = @logger
View
6 railties/lib/rails/rack/logger.rb
@@ -1,9 +1,9 @@
-require 'rails/subscriber'
+require 'rails/log_subscriber'
module Rails
module Rack
# Log the request started and flush all loggers after it.
- class Logger < Rails::Subscriber
+ class Logger < Rails::LogSubscriber
def initialize(app)
@app = app
end
@@ -26,7 +26,7 @@ def before_dispatch(env)
end
def after_dispatch(env)
- Rails::Subscriber.flush_all!
+ Rails::LogSubscriber.flush_all!
end
end
View
4 railties/lib/rails/railtie.rb
@@ -32,8 +32,8 @@ def railtie_names
subclasses.map { |p| p.railtie_name }
end
- def subscriber(subscriber)
- Rails::Subscriber.add(railtie_name, subscriber)
+ def log_subscriber(log_subscriber)
+ Rails::LogSubscriber.add(railtie_name, log_subscriber)
end
def rake_tasks(&blk)
View
2  railties/test/application/initializers/notifications_test.rb
@@ -28,7 +28,7 @@ def wait
ActiveSupport::Notifications.notifier.wait
end
- test "rails subscribers are added" do
+ test "rails log_subscribers are added" do
add_to_config <<-RUBY
config.colorize_logging = false
RUBY
View
119 railties/test/log_subscriber_test.rb
@@ -0,0 +1,119 @@
+require 'abstract_unit'
+require 'rails/log_subscriber/test_helper'
+
+class MyLogSubscriber < Rails::LogSubscriber
+ attr_reader :event
+
+ def some_event(event)
+ @event = event
+ info event.name
+ end
+
+ def foo(event)
+ debug "debug"
+ info "info"
+ warn "warn"
+ end
+
+ def bar(event)
+ info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}"
+ end
+
+ def puke(event)
+ raise "puke"
+ end
+end
+
+class SyncLogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
+
+ def setup
+ super
+ @log_subscriber = MyLogSubscriber.new
+ Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil)
+ end
+
+ def teardown
+ super
+ Rails::LogSubscriber.log_subscribers.clear
+ Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil)
+ end
+
+ def instrument(*args, &block)
+ ActiveSupport::Notifications.instrument(*args, &block)
+ end
+
+ def test_proxies_method_to_rails_logger
+ @log_subscriber.foo(nil)
+ assert_equal %w(debug), @logger.logged(:debug)
+ assert_equal %w(info), @logger.logged(:info)
+ assert_equal %w(warn), @logger.logged(:warn)
+ end
+
+ def test_set_color_for_messages
+ Rails::LogSubscriber.colorize_logging = true
+ @log_subscriber.bar(nil)
+ assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last
+ end
+
+ def test_does_not_set_color_if_colorize_logging_is_set_to_false
+ @log_subscriber.bar(nil)
+ assert_equal "cool, isn't it?", @logger.logged(:info).last
+ end
+
+ def test_event_is_sent_to_the_registered_class
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ assert_equal %w(my_log_subscriber.some_event), @logger.logged(:info)
+ end
+
+ def test_event_is_an_active_support_notifications_event
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ assert_kind_of ActiveSupport::Notifications::Event, @log_subscriber.event
+ end
+
+ def test_does_not_send_the_event_if_it_doesnt_match_the_class
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.unknown_event"
+ wait
+ # If we get here, it means that NoMethodError was raised.
+ end
+
+ def test_does_not_send_the_event_if_logger_is_nil
+ Rails.logger = nil
+ @log_subscriber.expects(:some_event).never
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ end
+
+ def test_flushes_loggers
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ Rails::LogSubscriber.flush_all!
+ assert_equal 1, @logger.flush_count
+ end
+
+ def test_flushes_the_same_logger_just_once
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ Rails::LogSubscriber.add :another, @log_subscriber
+ Rails::LogSubscriber.flush_all!
+ wait
+ assert_equal 1, @logger.flush_count
+ end
+
+ def test_logging_does_not_die_on_failures
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.puke"
+ instrument "my_log_subscriber.some_event"
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_equal 'my_log_subscriber.some_event', @logger.logged(:info).last
+
+ assert_equal 1, @logger.logged(:error).size
+ assert_equal 'Could not log "my_log_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
+ end
+end
View
8 railties/test/railties/railtie_test.rb
@@ -51,12 +51,12 @@ class Bar < Rails::Railtie
assert_equal "bar", Bar.config.foo.bar
end
- test "railtie can add subscribers" do
+ test "railtie can add log subscribers" do
begin
- class Foo < Rails::Railtie ; subscriber(Rails::Subscriber.new) ; end
- assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo]
+ class Foo < Rails::Railtie ; log_subscriber(Rails::LogSubscriber.new) ; end
+ assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[:foo]
ensure
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
end
end
View
119 railties/test/subscriber_test.rb
@@ -1,119 +0,0 @@
-require 'abstract_unit'
-require 'rails/subscriber/test_helper'
-
-class MySubscriber < Rails::Subscriber
- attr_reader :event
-
- def some_event(event)
- @event = event
- info event.name
- end
-
- def foo(event)
- debug "debug"
- info "info"
- warn "warn"
- end
-
- def bar(event)
- info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}"
- end
-
- def puke(event)
- raise "puke"
- end
-end
-
-class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
-
- def setup
- super
- @subscriber = MySubscriber.new
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def teardown
- super
- Rails::Subscriber.subscribers.clear
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def instrument(*args, &block)
- ActiveSupport::Notifications.instrument(*args, &block)
- end
-
- def test_proxies_method_to_rails_logger
- @subscriber.foo(nil)
- assert_equal %w(debug), @logger.logged(:debug)
- assert_equal %w(info), @logger.logged(:info)
- assert_equal %w(warn), @logger.logged(:warn)
- end
-
- def test_set_color_for_messages
- Rails::Subscriber.colorize_logging = true
- @subscriber.bar(nil)
- assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last
- end
-
- def test_does_not_set_color_if_colorize_logging_is_set_to_false
- @subscriber.bar(nil)
- assert_equal "cool, isn't it?", @logger.logged(:info).last
- end
-
- def test_event_is_sent_to_the_registered_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_equal %w(my_subscriber.some_event), @logger.logged(:info)
- end
-
- def test_event_is_an_active_support_notifications_event
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_kind_of ActiveSupport::Notifications::Event, @subscriber.event
- end
-
- def test_does_not_send_the_event_if_it_doesnt_match_the_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.unknown_event"
- wait
- # If we get here, it means that NoMethodError was raised.
- end
-
- def test_does_not_send_the_event_if_logger_is_nil
- Rails.logger = nil
- @subscriber.expects(:some_event).never
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- end
-
- def test_flushes_loggers
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.flush_all!
- assert_equal 1, @logger.flush_count
- end
-
- def test_flushes_the_same_logger_just_once
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.add :another, @subscriber
- Rails::Subscriber.flush_all!
- wait
- assert_equal 1, @logger.flush_count
- end
-
- def test_logging_does_not_die_on_failures
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.puke"
- instrument "my_subscriber.some_event"
- wait
-
- assert_equal 1, @logger.logged(:info).size
- assert_equal 'my_subscriber.some_event', @logger.logged(:info).last
-
- assert_equal 1, @logger.logged(:error).size
- assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.