Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove assets loading from error logs

Is it possible to remove the loading of assets ( images for example ) from the logs? I would like to have just the view rendering in my log + with the activerecord stuff and no other things that distract.

Can you setup the logger to remove certain elements from the log such as asset loading? thx

like image 535
Rubytastic Avatar asked Jan 28 '12 13:01

Rubytastic


1 Answers

You can add initializer quite_assets.rb with:

def is_windows?
    RUBY_PLATFORM['mswin32'] || RUBY_PLATFORM['mingw'] || RUBY_PLATFORM['cygwin']
end

destination = is_windows?? 'NUL' : '/dev/null'

Rails.application.assets.logger = Logger.new(destination)
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
like image 125
Mikhail Nikalyukin Avatar answered Oct 03 '22 17:10

Mikhail Nikalyukin