Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i turn off assets logging in development mode, in rails? [duplicate]

I tried:

config.assets.logger = nil

And

config.assets.logger = false

Any clue how to get those pesky logs out?

like image 262
Kamilski81 Avatar asked Jun 12 '12 16:06

Kamilski81


People also ask

How do you Precompile Rails assets?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What is assets Precompile?

rails assets:precompile is the task that does the compilation (concatenation, minification, and preprocessing). When the task is run, Rails first looks at the files in the config.assets.precompile array. By default, this array includes application.js and application.css .

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.


1 Answers

place this in config/initializers/quiet_assets.rb

if Rails.env.development?
  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'] =~ %r{^/assets/}
      call_without_quiet_assets(env)
    ensure
      Rails.logger.level = previous_level
    end
    alias_method_chain :call, :quiet_assets
  end
end

its a fairly common solution to this problem

also can just use a gem

gem 'quiet_assets', :group => :development
like image 180
TheIrishGuy Avatar answered Oct 04 '22 17:10

TheIrishGuy