Class: Frankenstein::Server::WEBrickLogger
- Inherits:
-
Object
- Object
- Frankenstein::Server::WEBrickLogger
- 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 injectprogname
. - 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
-
#<<(msg) ⇒ Object
Simulate the "append literal message" feature.
-
#initialize(logger:, progname: "WEBrick", access_log_priority: Logger::DEBUG) ⇒ WEBrickLogger
constructor
A new instance of WEBrickLogger.
Constructor Details
#initialize(logger:, progname: "WEBrick", access_log_priority: Logger::DEBUG) ⇒ WEBrickLogger
Returns a new instance of WEBrickLogger.
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 |