Minimize or disable WEBrick logging

Posted by Bob Showalter Mon, 25 Jun 2007 02:22:00 GMT

I wrote a simple application today that used WEBrick servlets to serve up some content, and I wanted to minimize the logging that WEBrick puts out.

There are two kings of logging used by WEBrick:

  • Server logging, which is controlled by the :Server parameter passed to WEBrick::HTTPServer.new. This uses syslog-style log levels.
  • Access logging, which is controlled by the :AccessLog parameter. This logs each request, and is similar to the Apache access log.

The default server log level is INFO, but I wanted to change it to WARN. I also wanted to disable Access logging altogether.

Here’s what I ended up using:
include WEBrick
server = HTTPServer.new(
  :Port => 8000,
  :Logger => Log.new(nil, BasicLog::WARN),
  :AccessLog => []
)
Now the server is silent unless an unexpected problem occurs.
Comments

Leave a response

Comments