Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Served asset log messages are pretty annoying! :) #2639

Closed
rafamvc opened this Issue · 175 comments

141 participants

Rafael Cardoso Istvan Pusztai Chris Mealy Mathieu Robardey Igor Ranieri Elland Anezio Marques de Campos Junior Luiz Fonseca Raoni Boaventura Yuri Smirnov Justin Dell Bhavin Celso Dantas Tim Riendeau Federico Soria Guillermo Iguaran Gilson Ferraz César Tom Coleman David Reese Olivier Kaluzny Johan Kim shadowbq Rodion Karl Freeman Evgenii Neumerzhitckii and others
Rafael Cardoso

Is there a setup to disable them?
I tried

config.assets.logger = nil

but no luck.

 GET "/assets/application.css" for 127.0.0.1 at 2011-08-22 11:19:59 -0700
Served asset /application.css - 304 Not Modified (1ms)
Mathieu Robardey

+1, this log takes up too much space in my terminal (~100 lines per request !)

Igor Ranieri Elland

+1

Raoni Boaventura

+1

Yuri Smirnov

+1

Bhavin

+1. There should be a way to control this or configure asset logger like we do with active_record, action_controller etc. Is it using Rails.logger?. Overriding Rails.logger is apparently not having any impact on "Served asset" calls. Swaping Rails::Rack::Logger too didn't help..

Istvan Pusztai

I use tail -f log/development.log | grep -vE "(^\s*$|asset)" until this gets fixed...

Rafael Cardoso

That is +12 so far... I unfortunately can't code this myself, so if any one wants to make a patch... :D

Guillermo Iguaran
GET "/assets/application.css" for 127.0.0.1 at 2011-08-22 11:19:59 -0700
Served asset /application.css - 304 Not Modified (1ms)

The first line is logged by Rails, the second one by Sprockets. You can shut up Sprockets logging:

Rails.application.assets.logger = Logger.new '/dev/null'

Sorry but you couldn't do same for the first line

Gilson Ferraz César

+1

David Reese

(specific instructions for suggeston from @guilleiguaran):

Just put this in your environment file (eg development.rb) to disable the sprockets log:

  config.after_initialize do |app|
    app.assets.logger = Logger.new('/dev/null')
  end
shadowbq

3.1 (only) (3.2 breaks before_dipatch)
app\config\initializers\quiet_assets.rb

Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
  def before_dispatch_with_quiet_assets(env)
    before_dispatch_without_quiet_assets(env) unless env['PATH_INFO'].index("/assets/") == 0
  end
  alias_method_chain :before_dispatch, :quiet_assets
end

3.2 Rails - Rack root tap approach
app\config\initializers\quiet_assets.rb

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 

(So much thanks to for the answer and code 'choonkeat'
Reference: http://stackoverflow.com/questions/6312448/how-to-disable-logging-of-asset-pipeline-sprockets-messages-in-rails-3-1
Learn more about tap in Ruby 1.9: http://ruby-doc.org/core/Object.html

Rodion

+1

Mathieu Robardey

@shadowbq thank you, work very well

Eric Thomas
et commented

+1

Alex Tambellini

+1

Mike Perham

This is hugely annoying to us too. It would be nice to see some movement on this issue.

takesi

+1

Chris Kelly

+1

Andrew Korzhuev

+1, what the heck is this "+1" thing? is it to make finding useful comments really hard?

Istvan Pusztai

@andrusha For the lack of the ability to upvote/prioritize issues, +1 basically means "me too."

Toshinori Kajihara
Collaborator

+1

Daniel Beattie

+1

Rich

+1

Maxime Garcia

+1

Very annoying !

sadgb

+1

Dave Rapin

+1

jhlllnd

+1

Vinny Salvati

+1

Ratnadeep Deshmane

+1

Ben Reubenstein

+1

Yorick Imthorn

+1

Kennon Ballou

+1

Jeroen Oldenburger

@shadowbq works well, thanks a lot!

Mikhail Nikalyukin

+1

John Wong

+1

Jeena Paradies

+1

Roland Moriz

+1 :+1:

Daniel Lv

+1

Leon Guan

+1

Leif Ringstad

+1

zefir

+1

Leon Du

+1
it's annoying!

altuure

+1

Javier Cuevas

+1

Janusz Pietrzyk

@shadowbq 's solution doesn't work anymore in 3.2.0.rc1 and rc2, since the introduction of the tagged logging thing. Couldn't figure out any alternative :/

shadowbq
Dmitriy Kiriyenko

+1, please

James Healy

+1

Rafael Mendonça França

I think that this issue can be closed now. cc/ @josevalim

Guillermo Iguaran

Now, setting config.assets.logger = false will silent served asset log messages, not setting it or setting nil will default to Rails.logger. This was done in e275817 and 226783d

Ratnadeep Deshmane

is it in for rails 3.1.3 ?

Guillermo Iguaran

is in 3-2-stable and master branch but you can ask for backport to 3-1-stable for include it in rails 3.1.4

Rafael Mendonça França

No. Will be released in the next release of 3-2-stable branch

Ratnadeep Deshmane

as of now, rails 3.2 is released. I upgraded my app to rails 3.2 and it sill shows assets in logs though i am using config.assets.logger = false

Janusz Pietrzyk

Well it doesn't show the Served asset log info, but the GET's are still there making the noise. For now you have to either use the hax provided above or do rake assets:precompile every time you make a change to your assets, so the issue isn't completly resolved.

Ratnadeep Deshmane

yes setting config.assets.logger = false doesn't show server log info.
but the other issue is - setting this up, causes sprockets to fail, as it finds env.logger to be true/false, and tried calling its methods on true/false.


NoMethodError (undefined method `error' for true:TrueClass):
  sprockets (2.1.2) lib/sprockets/server.rb:70:in `rescue in call'
  sprockets (2.1.2) lib/sprockets/server.rb:23:in `call'
  journey (1.0.0) lib/journey/router.rb:60:in `block in call'
  journey (1.0.0) lib/journey/router.rb:48:in `each'
  journey (1.0.0) lib/journey/router.rb:48:in `call'
  actionpack (3.2.0) lib/action_dispatch/routing/route_set.rb:570:in `call'
  sass (3.1.12) lib/sass/plugin/rack.rb:54:in `call'
  warden (1.1.0) lib/warden/manager.rb:35:in `block in call'
  warden (1.1.0) lib/warden/manager.rb:34:in `catch'
  warden (1.1.0) lib/warden/manager.rb:34:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.0) lib/rack/etag.rb:23:in `call'
  rack (1.4.0) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.0) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.0) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  activerecord (3.2.0) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.0) lib/active_support/callbacks.rb:405:in `_run__588329307__call__371483043__callbacks'
  activesupport (3.2.0) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.0) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.0) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.0) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.0) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.0) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.0) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.2.0) lib/rails/engine.rb:479:in `call'
  railties (3.2.0) lib/rails/application.rb:220:in `call'
  rack (1.4.0) lib/rack/content_length.rb:14:in `call'
  railties (3.2.0) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.0) lib/rack/handler/webrick.rb:59:in `service'
  /home/rtdp/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rtdp/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rtdp/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Guillermo Iguaran

@rtdp the error is reproducible only when you set config.assets.logger = true, right?
Setting it to false should not set any logger to Sprockets.

@Metallord @rtdp The Served asset lines and Compiling lines are logged by Sprockets, the Started GET one are logged by ActionPack. config.assets.logger = false only can be used to silent Sprockets logs.

If you want to silent the request logs you can patch Rails::Rack::Logger in an initializer:

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 

For details about why we won't silent the request logs read this: #3795 (comment)

Ratnadeep Deshmane

@guilleiguaran yes you were right about true/false, it only reproduces on true. Thanks!!

Marko Postma

+1

Erick Vanegas

Well, we still need a clean solution for silence GET logs too, hope we have this soon.

Zolzaya Erdenebaatar

+1

jokry

+1

Fabio Napoleoni

+1

Deleted user

+1

mori-dev

Andrew Korzhuev

(╯°□°)╯⤵

Jean Mertz

Wow, github badly needs a +1 button somewhere to "show your support". Reading issues full with +1 comments is getting messy.

Oh and, +1

Roland Moriz

:+1: : +1 :

Rafael Cardoso

@rafaelfranca do we need to reopen this issue? From what it says here tagged logging broke it.

Rafael Mendonça França

I don't think so. I'm using this option to remove the sprockets logs. But, the request logs will still be present. Look at this comment to see why we will not fix.

idontusegithub

Alright.

Everybody else, please stop +1! :) (At least until github puts a damn +1 button for issues)

Roland Moriz

:+1: :+1:
:-1: :-1:

Dmitry Vorotilin

that's why I've written https://github.com/evrone/quiet_assets for simple adding to project

Huan Son

+1!

5084PM

This thread illustrates just how painful it is to find something useful in the logs. +1

Marc-André Cournoyer

A cleaner way to fix this. Using a Rack middleware:

# Usage: in develoopment.rb
#
#   config.middleware.insert_before Rails::Rack::Logger, DisableAssetsLogger
#
class DisableAssetsLogger
  def initialize(app)
    @app = app
    Rails.application.assets.logger = Logger.new('/dev/null')
  end

  def call(env)
    previous_level = Rails.logger.level
    Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
    @app.call(env)
  ensure
    Rails.logger.level = previous_level
  end
end
Chew Choon Keat

To keep it in 1 file, append

Rails.application.config.middleware.insert_before Rails::Rack::Logger, DisableAssetsLogger if Rails.env.development?
Bluemont Labs

If you read the messages above (painful, I know) you can see that a fix has gone into the Rails master branch: 98081cb

If you want to see what branches contain this change, use git branch --contains 98081cbe06. Currently it is in master.

If you want to see what Rails releases contain this change, use git tag --contains 98081cbe06. As of this writing, there are no results, meaning this hasn't been released.

Fred Ngo

Thanks @macournoyer , I need that just in time! :)

Olivier El Mekki

@macournoyer Thanks, very useful.

I added possibility to activate/deactivate it on the fly (well, on server restarts, at least) with an environment variable :

class DisableAssetsLogger
  def initialize(app)
    unless ENV[ 'LOG_ASSETS' ]
      puts "Deactivating asset logging."
      puts "To see asset requests in log, start with LOG_ASSETS=true env variable."
    end

    @app = app
    Rails.application.assets.logger = Logger.new('/dev/null')
  end

  def call(env)
    previous_level = Rails.logger.level
    Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0 && ! ENV[ 'LOG_ASSETS' ]
    @app.call(env)
  ensure
    Rails.logger.level = previous_level
  end
end
Philipp Weissensteiner

Lets join the party :+1:

Zac Pierce

I just noticed this line in my development.rb:

config.assets.debug = true

If you set it to false, it stops the output of most of the 304's for the asset pipeline.

I only get these two:

Started GET "/assets/application.css" for 127.0.0.1 at 2012-09-03 23:45:39 -0500
Served asset /application.css - 304 Not Modified (2ms)

Started GET "/assets/application.js" for 127.0.0.1 at 2012-09-03 23:45:39 -0500
Served asset /application.js - 304 Not Modified (41ms)

as opposed to a logged request for each individual asset.

Elia Schito

@rtdp @guilleiguaran etc. using config.logger instead of true will fix the undefined method error

config.assets.logger = config.logger
Guillermo Iguaran

@ Everyone here, in Rails 3.2 and master you can do something like:

config.log_tags = [
  -> request { :assets if request.path.starts_with?(config.assets.prefix) },
  -> request { request.uuid }
]

And tail your logs ignoring the lines tagged with assets:

$ tail -100f log/development.log | grep -v assets

Thanks to @jeremy for the tip

Steve Klabnik
Collaborator

That's sweet, but it doesn't help with the output from rails s.

Vitaly Kushner

guys, just set config.assets.debug = false and be happy ;)

Olivier El Mekki

@vitaly The problem with that is that sometime, you may actually want to have asset logging. It's a bit sad to have to change codebase for that. Yes, I know, first world problem :)

With the middleware approach, this is doable, though ; just need to pass an environment variable to rails s.

Vitaly Kushner

@oelmekki well, nothing prevents you from only doing debug = false when some environment variable is not set ;)

Harris Novick

I really like @guilleiguaran's solution. grep -v

Paolo Montrasio

I put macournoyer's code in an initializer, followed by the line by choonkeat.
That made most all the log entries disappear with the exception of these messages:

WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

There is a thread in stackoverflow about that, here.

I followed their suggestions and removed those messages by adding gem "webrick", "1.3.1" to the group :development block of Gemfile. My rails output is readable now.

Lars

config.assets.debug = false
config.assets.logger = nil

Neither works for moi :/

Omnipresent

n00b question. Where should DisableAssetsLogger be placed? in initializer?

Lars
Lars
Martin Honermeyer

+1

Nathan Broadbent

Hi @Omnipresent, I've just released this as a gem, so you can add it your Gemfile:

gem 'disable_assets_logger', :group => :development
Ikuhide Nara aran19 referenced this issue in aran19/myapp
Closed

304 not modifiedログを消す方法 #1

rubytastic

if Rails.env.development?
ActiveRecord::Base.logger = Logger.new('/dev/null')
end

Inside initializer

Ola Tuvesson

@rafamvc (and others): My sprockets railtie (v3.2.11) checks

if config.assets.logger != false

Setting config.assets.logger to false - not nil - in development.rb got rid of the spam.

Huan Son

still on, bitchez

Huan Son

hate to check production logfile with

 tail -f log/production.log  -n 1000 | grep -v asset
Oleg Pudeyev

So when is this getting fixed in a usable way?

TinNT

tail -f log/development.log | grep -vE "(^$|asset)"

Huan Son

seriously. rails 4 beta and this still a bug.

#fml

Oz DiGennaro

I love it when someone else does the work. The 'nbroadbent' gem worked fine for me. rails 3.2.13.

Oz DiGennaro
Aleksei Maridashvili

+1

Anthony Williams antw referenced this issue from a commit in quintel/etflex
Anthony Williams antw Partially silence asset logging in development. fef57b1
Anthony Williams antw referenced this issue from a commit in quintel/etflex
Anthony Williams antw Partially silence asset logging in development. 40be3b1
Anthony Williams antw referenced this issue from a commit in quintel/etflex
Anthony Williams antw Partially silence asset logging in development. 0a71bd6
Glenn / devalias alias1 referenced this issue in cantino/huginn
Closed

Web log spam #365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.