Skip to content
Browse files

Silencing asset queries

  • Loading branch information...
1 parent 584441e commit 3c66a9d726dd3daf0d0758c4ccc25052bc1be26c @jcasimir jcasimir committed Mar 22, 2012
Showing with 27 additions and 12 deletions.
  1. +1 −1 app/models/article.rb
  2. +0 −11 config/initializers/quiet_assets.rb
  3. +26 −0 config/initializers/silence_assets.rb
View
2 app/models/article.rb
@@ -6,7 +6,7 @@ class Article < ActiveRecord::Base
has_many :taggings
has_many :tags, :through => :taggings
- default_scope :include => [:comments, :tags]
+ #default_scope :include => [:comments, :tags]
def to_s
return title
View
11 config/initializers/quiet_assets.rb
@@ -1,11 +0,0 @@
-Rails.application.assets.logger = Logger.new('/dev/null')
-Rails::Rack::Logger.class_eval do
- def call_with_quiet_assets(env)
- previous_level = Rails.logger.level
- Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
- call_without_quiet_assets(env).tap do
- Rails.logger.level = previous_level
- end
- end
- alias_method_chain :call, :quiet_assets
-end
View
26 config/initializers/silence_assets.rb
@@ -0,0 +1,26 @@
+class NullLogger < Logger
+ def initialize(*args); end
+ def write(*input); true; end
+end
+
+Rails.application.assets.logger = NullLogger.new
+
+class Rails::Rack::Logger
+ alias_method :standard_call, :call
+
+ def temporary_level(level)
+ initial_level = Rails.logger.level
+ Rails.logger.level = level
+ yield
+ ensure
+ Rails.logger.level = initial_level
+ end
+
+ def call(env)
+ if env['PATH_INFO'] =~ /^\/assets\//
+ temporary_level(Logger::ERROR) { standard_call(env) }
+ else
+ standard_call(env)
+ end
+ end
+end

0 comments on commit 3c66a9d

Please sign in to comment.
Something went wrong with that request. Please try again.