1

I just upgraded an app from Ruby 2.3 / Rails 4.2 to Ruby 2.5.3 / Rails 5.2.2. The upgrade went smoothly but now when I test making calls in my development server, I notice that each page request generates two extra log lines in STDOUT (but not in my Rails log/development.log) that I infer are coming from WEBrick, not Rails. I'd like to remove them. See below for example, the first line is the Rails request log (I want to keep that one) and the following two are ugly and redundant:

...
■ [GET /guiding_principles] params={} user=51 (Topher Hunt) status=200 duration=505.81ms
::1 - - [14/Jan/2019:21:22:45 CET] "GET /guiding_principles HTTP/1.1" 200 8840
http://localhost:3000/guiding_principles -> /guiding_principles
...

If you're starting a fresh WEBrick server, it looks like there's ways to configure or probably silence logging, see e.g. here and here. But I don't see a clear way (or any guidance on how) to do that in a Rails context.

How can I tell WEBrick not to log anything on each request?

Topher Hunt
  • 4,404
  • 2
  • 27
  • 51
  • 1
    I would really focus on ditching WEBrick in favor of Puma which is the default server when you create a new Rails 5 app. Puma unlike WEBrick is actually a production grade server and using the same server for development and production is good for [dev/prod parity](https://12factor.net/dev-prod-parity). – max Jan 15 '19 at 11:48
  • https://devcenter.heroku.com/articles/ruby-default-web-server#why-not-webrick – max Jan 15 '19 at 11:56
  • Oh thanks @max, I'm still learning all the changes and had no idea that Puma was now default. That's great news! – Topher Hunt Jan 16 '19 at 12:44
  • Installing puma gem worked with me https://stackoverflow.com/a/42405410/1770571 – Salma Gomaa Apr 10 '22 at 14:24

1 Answers1

2

I found a monkeypatch that does an adequate job of this. With this patch in place, no per-request log lines will be produced, but the init lines (reminding you that you're running WEBrick) are still shown.

# (config/initializers/webrick.rb)
# Silence WEBrick's verbose per-request logging
# See https://github.com/ruby/ruby : /lib/webrick/httpserver.rb
if Rails.env.development?
  require 'webrick'

  module WEBrick
    class HTTPServer
      def access_log(a, b, c)
        nil
      end
    end
  end
end
Topher Hunt
  • 4,404
  • 2
  • 27
  • 51