Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
rafamvc opened this Issue · 177 comments
@rafamvc

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

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

@Elland

+1

@raonibr

+1

@tycooon

+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

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

@rafamvc

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

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

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

+1

@foohey

@shadowbq thank you, work very well

@et
et commented

+1

@atambo

+1

@mperham

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

@auxout

+1

@ckdake

+1

@andrusha

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

@istvanp

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

@kennyj
Collaborator

+1

@danbt79

+1

@rds

+1

@maximeg

+1

Very annoying !

@sadgb

+1

@rapind

+1

@jhlllnd

+1

@vsalvati

+1

@rtdp

+1

@benr75

+1

@kciroy

+1

@kennon

+1

@jeroenoldenburger

@shadowbq works well, thanks a lot!

@dpsk

+1

@namor

+1

@jeena

+1

@rmoriz

+1 :+1:

@lgn21st

+1

@pzgz

+1

@leifcr

+1

@zefir

+1

@leondu

+1
it's annoying!

@altuure

+1

@javiercr

+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

+1

@rafaelfranca

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

@guilleiguaran

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

is it in for rails 3.1.3 ?

@guilleiguaran

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

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

@rtdp

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

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

@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

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

@marksten

+1

@eveevans

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

@zolzaya

+1

@jokry

+1

@fabn

+1

@ghost

+1

@mori-dev

@andrusha

(╯°□°)╯⤵

@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

:+1: : +1 :

@rafamvc

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

@rafaelfranca

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

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

@route

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

@fu-media

+1!

@5084PM

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

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

@oelmekki

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

Lets join the party :+1:

@zac0351

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

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

config.assets.logger = config.logger
@guilleiguaran

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

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

@vitaly

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

@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

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

@flunder

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

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

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

@rubytastic

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

Inside initializer

@mikrogroove

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

@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

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.

@ozdigennaro
@lexigen

+1

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

Web log spam #365

@matthewd matthewd locked and limited conversation to collaborators
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.