Skip to content

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

Closed
rafamvc opened this Issue Aug 22, 2011 · 177 comments
@rafamvc
rafamvc commented Aug 22, 2011

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)
@istvanp
istvanp commented Sep 2, 2011

Bump x9+ (see question @ stackoverflow)

@chrismealy

+1

@foohey
foohey commented Sep 6, 2011

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

@Elland
Elland commented Sep 6, 2011

+1

@aneziocampos

+1

@luizfonseca

+1

@raonibr
raonibr commented Sep 6, 2011

+1

@tycooon
tycooon commented Sep 7, 2011

+1

@justindell

+1

@bhavinkamani

+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..

@istvanp
istvanp commented Sep 10, 2011

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

@celsodantas

+1

@triendeau

+1

@rafamvc
rafamvc commented Sep 12, 2011

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

@fedesoria

+1

@guilleiguaran
Ruby on Rails member
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

@gferraz
gferraz commented Sep 19, 2011

+1

@tmeasday

+1

@whatcould

(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
@kaluznyo

+1

@hiphapis

+1

@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

@sars
sars commented Oct 1, 2011

+1

@karlfreeman

+1

@evgenyneu

+1

@foohey
foohey commented Oct 10, 2011

@shadowbq thank you, work very well

@ffissore

+1

@et
et commented Oct 13, 2011

+1

@atambo
atambo commented Oct 13, 2011

+1

@mperham
mperham commented Oct 13, 2011

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

@auxout
auxout commented Oct 15, 2011

+1

@erlingur

+1

@ckdake
ckdake commented Oct 17, 2011

+1

@danieltdt

+1

@andrusha

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

@istvanp
istvanp commented Oct 19, 2011

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

@chipchiq

+1

@kennyj
kennyj commented Oct 20, 2011

+1

@danbt79
danbt79 commented Oct 21, 2011

+1

@rds
rds commented Oct 21, 2011

+1

@stanislaw

+1

@maximeg
maximeg commented Oct 21, 2011

+1

Very annoying !

@sadgb
sadgb commented Oct 24, 2011

+1

@MadsBuus

+1

@christoffer

+1

@rapind
rapind commented Oct 27, 2011

+1

@jhlllnd
jhlllnd commented Oct 27, 2011

+1

@cncardoso

+1

@danchenkov

+1

@vsalvati
vsalvati commented Nov 2, 2011

+1

@jeremyhaile

+1

@rtdp
rtdp commented Nov 2, 2011

+1

@Metallord

+1

@benr75
benr75 commented Nov 3, 2011

+1

@kciroy
kciroy commented Nov 6, 2011

+1

@kennon
kennon commented Nov 7, 2011

+1

@jeroenoldenburger

@shadowbq works well, thanks a lot!

@lekevicius

+1

@kyledecot

+1

@dpsk
dpsk commented Nov 9, 2011

+1

@courtsimas

+1

@speedmax

+1

@namor
namor commented Nov 15, 2011

+1

@jeena
jeena commented Nov 17, 2011

+1

@rmoriz
rmoriz commented Nov 20, 2011

+1 👍

@axelerator

+1

@lgn21st
lgn21st commented Nov 21, 2011

+1

@pzgz
pzgz commented Nov 22, 2011

+1

@leifcr
leifcr commented Nov 22, 2011

+1

@zefir
zefir commented Nov 27, 2011

+1

@leondu
leondu commented Dec 14, 2011

+1
it's annoying!

@altuure
altuure commented Dec 18, 2011

+1

@elitheeli

+1

@sapronlee

+1

@mferrier

+1

@javiercr
javiercr commented Jan 1, 2012

+1

@Metallord

@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

@yob
yob commented Jan 13, 2012

+1

@jcalvert

+1

@rafaelfranca
Ruby on Rails member

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

@guilleiguaran
Ruby on Rails member

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

@rtdp
rtdp commented Jan 18, 2012

is it in for rails 3.1.3 ?

@guilleiguaran
Ruby on Rails member

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

@rafaelfranca
Ruby on Rails member

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

@rtdp
rtdp commented Jan 24, 2012

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

@Metallord

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.

@rtdp
rtdp commented Jan 24, 2012

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'
@guilleiguaran
Ruby on Rails member

@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)

@rtdp
rtdp commented Jan 24, 2012

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

@bluerabbit

+1

@marksten
marksten commented Mar 6, 2012

+1

@eveevans
eveevans commented Mar 6, 2012

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

@tysontate

+1

@zolzaya
zolzaya commented Mar 9, 2012

+1

@jokry
jokry commented Mar 11, 2012

+1

@nathanclark

+2

@fabn
fabn commented Mar 22, 2012

+1

@pedrocarrico

+1

@assembler

+1

@seanarnold

+1

@coorasse

+1

@ghost
ghost commented Apr 1, 2012

+1

@mori-dev
mori-dev commented Apr 7, 2012

@andrusha
andrusha commented Apr 7, 2012

(╯°□°)╯⤵

@JeanMertz

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

Oh and, +1

@rmoriz
rmoriz commented Apr 13, 2012

👍 : +1 :

@spangenberg

+1

@rafamvc
rafamvc commented Apr 13, 2012

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

@rafaelfranca
Ruby on Rails member

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)

@rmoriz
rmoriz commented Apr 14, 2012

👍 :+1:
👎 :-1:

@route
route commented Apr 14, 2012

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

@knightq
knightq commented May 17, 2012

👍

@fu-media

+1!

@leehambley

+1

@hishma
hishma commented Jun 6, 2012

👍

@5084PM
5084PM commented Jun 25, 2012

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

@macournoyer

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
@choonkeat

To keep it in 1 file, append

Rails.application.config.middleware.insert_before Rails::Rack::Logger, DisableAssetsLogger if Rails.env.development?
@davidvarney

-1

@bluemont

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.

@fredngo
fredngo commented Jul 20, 2012

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

@oelmekki
oelmekki commented Aug 1, 2012

@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
@murphyslaw

+1

@wpp
wpp commented Aug 16, 2012

Lets join the party 👍

@zac0351
zac0351 commented Sep 4, 2012

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
elia commented Sep 22, 2012

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

config.assets.logger = config.logger
@guilleiguaran
Ruby on Rails member

@ 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

@steveklabnik
Ruby on Rails member

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

@zoubeiri

+1

@vitaly
vitaly commented Oct 15, 2012

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

@oelmekki

@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
vitaly commented Oct 15, 2012

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

@lightyrs

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

@dickeyxxx

+1

@gamafranco

+1

@pmontrasio

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.

@darthdeus

+1

@flunder
flunder commented Nov 6, 2012

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

Neither works for moi :/

@Omnipresent

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

@flunder
@flunder
@djmaze
djmaze commented Dec 5, 2012

+1

@ndbroadbent

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

gem 'disable_assets_logger', :group => :development
@aran19 aran19 referenced this issue in aran19/myapp Dec 24, 2012
Closed

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

@fu-media

+1

@rubytastic

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

Inside initializer

@clickworkorange

@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.

@jaredbrown

👍

@findrails

+1

@fu-media

still on, bitchez

@fu-media

hate to check production logfile with

 tail -f log/production.log  -n 1000 | grep -v asset
@p-originate

So when is this getting fixed in a usable way?

@TinNT
TinNT commented May 14, 2013

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

@fu-media

seriously. rails 4 beta and this still a bug.

#fml

@ozdigennaro

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

@tinderfields

+1

@earlonrails

👍

@DavideMiozzi

+1

@ozdigennaro
@acasajus

+1

@lexigen
lexigen commented Oct 30, 2013

+1

@antw antw added a commit to quintel/etflex that referenced this issue Dec 16, 2013
@antw antw Partially silence asset logging in development. fef57b1
@antw antw added a commit to quintel/etflex that referenced this issue Dec 17, 2013
@antw antw Partially silence asset logging in development. 40be3b1
@AndrewBelt

+1

@philipp-spiess

👍

@antw antw added a commit to quintel/etflex that referenced this issue Feb 25, 2014
@antw antw Partially silence asset logging in development. 0a71bd6
@alias1 alias1 referenced this issue in cantino/huginn Jun 3, 2014
Closed

Web log spam #365

@iloveitaly

👍

@deeTEEcee

+1

@matthewd matthewd locked and limited conversation to collaborators Apr 5, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Something went wrong with that request. Please try again.