diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/log_subscriber.rb | 34 | ||||
-rw-r--r-- | railties/lib/rails/log_subscriber/test_helper.rb | 1 |
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 |