From 5a6ea535145270751bdf712a6e5c489650765ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 18 Jan 2012 14:05:36 -0300 Subject: [PATCH] ActionView now has its own logger --- actionpack/CHANGELOG.md | 2 ++ actionpack/lib/action_view/base.rb | 1 + actionpack/lib/action_view/log_subscriber.rb | 3 +-- actionpack/lib/action_view/railtie.rb | 4 ++++ actionpack/test/controller/render_test.rb | 3 ++- actionpack/test/template/log_subscriber_test.rb | 4 +--- railties/guides/source/configuring.textile | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 6bff4700032b0..382a3cbd1dc13 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,4 +1,6 @@ ## Rails 4.0.0 (unreleased) ## +* Add `config.action_view.logger` to configure logger for ActionView. *Rafael França* + * Deprecated ActionController::Integration in favour of ActionDispatch::Integration * Deprecated ActionController::IntegrationTest in favour of ActionDispatch::IntegrationTest diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 0b026882aecff..122dc9db7f3ae 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -143,6 +143,7 @@ class Base class_attribute :helpers class_attribute :_routes + class_attribute :logger class << self delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB' diff --git a/actionpack/lib/action_view/log_subscriber.rb b/actionpack/lib/action_view/log_subscriber.rb index bf90d012bf077..cc3a871576a18 100644 --- a/actionpack/lib/action_view/log_subscriber.rb +++ b/actionpack/lib/action_view/log_subscriber.rb @@ -12,9 +12,8 @@ def render_template(event) alias :render_partial :render_template alias :render_collection :render_template - # TODO: Ideally, ActionView should have its own logger so it does not depend on AC.logger def logger - ActionController::Base.logger if defined?(ActionController::Base) + ActionView::Base.logger end protected diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb index 80391d72cc009..43371a1c49a5d 100644 --- a/actionpack/lib/action_view/railtie.rb +++ b/actionpack/lib/action_view/railtie.rb @@ -8,6 +8,10 @@ class Railtie < Rails::Railtie config.action_view.stylesheet_expansions = {} config.action_view.javascript_expansions = { :defaults => %w(jquery jquery_ujs) } + initializer "action_view.logger" do + ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger } + end + initializer "action_view.cache_asset_ids" do |app| unless app.config.cache_classes ActiveSupport.on_load(:action_view) do diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index d4363b2cb7c07..fef9fbb1755c0 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -692,7 +692,8 @@ def setup # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". super - @controller.logger = ActiveSupport::Logger.new(nil) + @controller.logger = ActiveSupport::Logger.new(nil) + ActionView::Base.logger = ActiveSupport::Logger.new(nil) @request.host = "www.nextangle.com" end diff --git a/actionpack/test/template/log_subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb index 752b0f23a85d0..1713ce935cd1c 100644 --- a/actionpack/test/template/log_subscriber_test.rb +++ b/actionpack/test/template/log_subscriber_test.rb @@ -8,7 +8,6 @@ class AVLogSubscriberTest < ActiveSupport::TestCase def setup super - @old_logger = ActionController::Base.logger @controller = Object.new @controller.stubs(:_prefixes).returns(%w(test)) @view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller) @@ -19,11 +18,10 @@ def setup def teardown super ActiveSupport::LogSubscriber.log_subscribers.clear - ActionController::Base.logger = @old_logger end def set_logger(logger) - ActionController::Base.logger = logger + ActionView::Base.logger = logger end def test_render_file_template diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index fb8031b16d697..f70e95c0e9874 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -342,7 +342,7 @@ Proc.new { |html_tag, instance| %Q(
#{html_tag}