aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-03-02 13:05:25 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-03-02 13:05:25 -0800
commitc2dbc391a9292e6f73cadce2f0ba1be871b29e82 (patch)
tree3956dbc83c4d87a2e889017fd14883e1ef6285da /railties
parentd434c5406846fb280b8a9d6ec40247b1f1b464c6 (diff)
downloadrails-c2dbc391a9292e6f73cadce2f0ba1be871b29e82.tar.gz
rails-c2dbc391a9292e6f73cadce2f0ba1be871b29e82.tar.bz2
rails-c2dbc391a9292e6f73cadce2f0ba1be871b29e82.zip
Have log subscribers subscribe to the actual events, so the subscriber doesn't subscribe to *every* event, so we can have events that are slow-ish but are not actually run in production.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application/configuration.rb13
-rw-r--r--railties/lib/rails/log_subscriber.rb34
-rw-r--r--railties/lib/rails/log_subscriber/test_helper.rb1
3 files changed, 27 insertions, 21 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index d6ad045294..a00f9c43ae 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -5,7 +5,7 @@ module Rails
class Configuration < ::Rails::Engine::Configuration
include ::Rails::Configuration::Deprecated
- attr_accessor :allow_concurrency, :cache_classes, :cache_store, :colorize_logging,
+ attr_accessor :allow_concurrency, :cache_classes, :cache_store,
:consider_all_requests_local, :dependency_loading,
:filter_parameters, :log_level, :logger, :metals,
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
@@ -14,7 +14,6 @@ module Rails
def initialize(*)
super
@allow_concurrency = false
- @colorize_logging = true
@filter_parameters = []
@dependency_loading = true
@serve_static_assets = true
@@ -81,6 +80,16 @@ module Rails
def log_level
@log_level ||= Rails.env.production? ? :info : :debug
end
+
+ def colorize_logging
+ @colorize_logging
+ end
+
+ def colorize_logging=(val)
+ @colorize_logging = val
+ Rails::LogSubscriber.colorize_logging = val
+ self.generators.colorize_logging = val
+ end
end
end
end \ No newline at end of file
diff --git a/railties/lib/rails/log_subscriber.rb b/railties/lib/rails/log_subscriber.rb
index 05cb70690a..0fbc19d89c 100644
--- a/railties/lib/rails/log_subscriber.rb
+++ b/railties/lib/rails/log_subscriber.rb
@@ -29,7 +29,7 @@ module Rails
# 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.
- #
+ #
# 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 LogSubscriber
@@ -50,31 +50,29 @@ module Rails
CYAN = "\e[36m"
WHITE = "\e[37m"
- def self.add(namespace, log_subscriber)
- log_subscribers[namespace.to_sym] = log_subscriber
- end
-
- def self.log_subscribers
- @log_subscribers ||= {}
- end
+ def self.add(namespace, log_subscriber, notifier = ActiveSupport::Notifications)
+ log_subscribers << log_subscriber
- def self.dispatch(args)
- namespace, name = args[0].split(".")
- return unless namespace && name
+ log_subscriber.public_methods(false).each do |event|
+ notifier.subscribe("#{namespace}.#{event}") do |*args|
+ next if log_subscriber.logger.nil?
- log_subscriber = log_subscribers[namespace.to_sym]
- if log_subscriber.respond_to?(name) && log_subscriber.logger
- begin
- 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}"
+ begin
+ log_subscriber.send(event, 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
end
+ def self.log_subscribers
+ @log_subscribers ||= []
+ end
+
# Flush all log_subscribers' logger.
def self.flush_all!
- loggers = log_subscribers.values.map(&:logger)
+ loggers = log_subscribers.map(&:logger)
loggers.uniq!
loggers.each { |l| l.flush if l.respond_to?(:flush) }
end
diff --git a/railties/lib/rails/log_subscriber/test_helper.rb b/railties/lib/rails/log_subscriber/test_helper.rb
index 9ede56cad4..02f5079462 100644
--- a/railties/lib/rails/log_subscriber/test_helper.rb
+++ b/railties/lib/rails/log_subscriber/test_helper.rb
@@ -43,7 +43,6 @@ module Rails
@notifier = ActiveSupport::Notifications::Notifier.new(queue)
Rails::LogSubscriber.colorize_logging = false
- @notifier.subscribe { |*args| Rails::LogSubscriber.dispatch(args) }
set_logger(@logger)
ActiveSupport::Notifications.notifier = @notifier