Class: Frankenstein::Server::WEBrickLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/frankenstein/server/webrick_logger.rb

Overview

Wrap a logger in behaviour that suits WEBrick's ideosyncratic style

There are a few things in the way that WEBrick interacts with the standard Logger class which don't suit modern logging practices:

  • It doesn't set a progname when logging, which makes it much harder to separate out WEBrick logs from other parts of your system.
  • Logging calls use the direct-pass approach to passing in strings, which degrades performance.
  • Access logging doesn't log with a priority, making it impossible to selectively log or not log access logs.
  • Access logging doesn't respect the logger formatting, making it much harder to parse logs than it should need to be.

This class is an attempt to capture all that aberrant behaviour and redirect it into more socially-acceptable forms:

  • All of the "priority" methods (warn, debug, etc) are wrapped to inject progname.
  • Access logging (or, more precisely, all calls to #<<) are intercepted and logged via the standard (format-respecting) calls, with the specified priority.

This will hopefully provide a more palatable WEBrick logging experience.

Instance Method Summary collapse

Constructor Details

#initialize(logger:, progname: "WEBrick", access_log_priority: Logger::DEBUG) ⇒ WEBrickLogger

Returns a new instance of WEBrickLogger.

Parameters:

  • logger (Logger)

    the actual Logger you want to send all of the log messages to.

  • progname (#to_s) (defaults to: "WEBrick")

    the progname you want to pass to all log messages that come through this wrapper.

  • access_log_priority (Fixnum) (defaults to: Logger::DEBUG)

    the priority at which to log access log messages. Any of the Logger::* priority constants will work Just Fine.



37
38
39
# File 'lib/frankenstein/server/webrick_logger.rb', line 37

def initialize(logger:, progname: "WEBrick", access_log_priority: Logger::DEBUG)
  @logger, @progname, @priority = logger, progname, access_log_priority
end

Instance Method Details

#<<(msg) ⇒ Object

Simulate the "append literal message" feature

Nothing goes into my logs without having appropriate metadata attached, so this just funnels these messages into the proper priority-based system.



69
70
71
# File 'lib/frankenstein/server/webrick_logger.rb', line 69

def <<(msg)
  @logger.add(@priority, msg, @progname)
end