What have you found for these years?

2012-03-19

Shut up Unicorn's Rack::CommonLogger for Rails' assets

This is definitely a very dirty hack to do this, but well,
I just can't resist anymore.
Caveat: This might not work in some versions of something!
Since it's heavily depending on the implementation.

This only applies to development mode because for production mode,
there's no interfering middlewares inserted by Unicorn (Rack).

unicorn.rb or rainbows.rb or zbatery.rb:
(Unicorn/Rainbows/Zbatery configuration file)
before_fork do |server, worker|
  # dirty hack to shut up Rack::CommonLogger for assets
  next unless ENV['RACK_ENV'] == 'development'
  app = server.app
  app = app.instance_variable_get(:@app) until
        app.kind_of?(Rack::CommonLogger) ||
        app.instance_variable_get(:@app).nil?

  app.instance_eval{
    @logger.puts "Silencing #{app.class} to #{IO::NULL}..."
    @logger = File.open(IO::NULL, 'w')
  } if app && IO.const_defined?(:NULL)
end

0 retries:

Post a Comment

All texts are licensed under CC Attribution 3.0