16

How can I disable messages from webrick echoed on to the terminal? For the INFO messages that appear at the beginning, I was able to disable it by setting the Logger parameter so as:

s = WEBrick::HTTPServer.new(
  Port: 3000,
  BindAddress: "localhost",
  Logger: WEBrick::Log.new("/dev/null"),
)

But I further want to disable the messages that look like:

localhost - - [17/Jun/2011:10:01:38 EDT] "GET .... HTTP/1.1" 200 0 http://localhost:3000/ -> .....

when a request is made from the web browser.

sawa
  • 165,429
  • 45
  • 277
  • 381
  • Try setting AccessLog to false in the config parameters, that is as far as I can see by [the source code](http://www.ruby-doc.org/stdlib/libdoc/webrick/rdoc/classes/WEBrick/HTTPServer.html#M009708). – Yet Another Geek Jun 17 '11 at 15:29
  • @Yet Another Geek I tried both setting it to false, then to nil, but it did not work. – sawa Jun 17 '11 at 15:33
  • @Yet Another Geek. When I set it to `[nil, nil]`, it worked. Your link helped. Thanks. – sawa Jun 17 '11 at 15:39

1 Answers1

23

Following the link to the source and suggestion provied by Yet Another Geek, I was able to figure out a way. Set the AccessLog parameter to [nil, nil] [] (Changed following suggestion by Robert Watkins).

s = WEBrick::HTTPServer.new(
  Port: 3000,
  BindAddress: "localhost",
  Logger: WEBrick::Log.new("/dev/null"),
  AccessLog: [],
)
sawa
  • 165,429
  • 45
  • 277
  • 381
  • 1
    Actually, you're better off passing an empty array for the AccessLog - e.g. AccessLog: [] Passing in nils just results in an error, which you can't see because you've sent your error logs to /dev/null – Robert Watkins Feb 04 '13 at 06:50
  • 2
    Use `Logger: WEBrick::Log.new(File.open(File::NULL, 'w'))` for a cross-platform solution – ens Jan 11 '16 at 22:31
  • For Rails edited `boot.rb`: https://github.com/rails/rails/issues/28968#issuecomment-327099731 – Pysis Mar 25 '19 at 17:09