Class: Kitchen::Logger::StreamLineFormatter
- Inherits:
-
Object
- Object
- Kitchen::Logger::StreamLineFormatter
- Defined in:
- lib/kitchen/logger.rb
Overview
Rewrites already-prefixed stream lines into the matching logger call.
Constant Summary collapse
- PREFIX_WIDTH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Width of every stream prefix in PREFIXES. All prefixes are the same width so that a line's severity is a fixed-offset lookup.
7- PREFIXES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps each stream prefix to the severity it denotes and whether the line must be replayed verbatim on sinks that cannot accept stream events.
{ "-----> " => [:banner, false], "D " => [:debug, true], "$$$$$$ " => [:warn, true], ">>>>>> " => [:error, false], "!!!!!! " => [:fatal, true], " " => [:info, false], }.freeze
Instance Method Summary collapse
-
#format(line) ⇒ void
private
Routes an already-prefixed stream line to the logger call matching its prefix, stripping the prefix before logging.
-
#initialize(logger) ⇒ StreamLineFormatter
constructor
A new instance of StreamLineFormatter.
Constructor Details
#initialize(logger) ⇒ StreamLineFormatter
Returns a new instance of StreamLineFormatter.
550 551 552 |
# File 'lib/kitchen/logger.rb', line 550 def initialize(logger) @logger = logger end |
Instance Method Details
#format(line) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Routes an already-prefixed stream line to the logger call matching its prefix, stripping the prefix before logging.
A hash lookup on the fixed-width prefix replaces a chain of anchored regexp matches, so an unprefixed line costs one lookup rather than six failed matches.
564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/kitchen/logger.rb', line 564 def format(line) severity, structured = PREFIXES[line[0, PREFIX_WIDTH]] if severity.nil? log_line(:info, line) elsif structured structured_line(severity, line[PREFIX_WIDTH..], line) else log_line(severity, line[PREFIX_WIDTH..]) end end |