Class: Captive::Presenter::LogLine
- Inherits:
-
Object
- Object
- Captive::Presenter::LogLine
- Defined in:
- lib/captive/presenter/log_line.rb
Overview
Parses a raw kubectl log line and renders it as a colorized terminal string.
Constant Summary collapse
- BRACKET_RE =
/\A\[(?:pod\/)?(?<pod>[^\/\]]+)(?:\/(?<container>[^\/\]]+))?\]\z/
Instance Method Summary collapse
- #call(raw_line) ⇒ Object
-
#initialize(app:, paint: Pastel.new) ⇒ LogLine
constructor
A new instance of LogLine.
Constructor Details
#initialize(app:, paint: Pastel.new) ⇒ LogLine
Returns a new instance of LogLine.
12 13 14 15 |
# File 'lib/captive/presenter/log_line.rb', line 12 def initialize(app:, paint: Pastel.new) @app = app @colorizer = LogColorizer.new(paint: paint) end |
Instance Method Details
#call(raw_line) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/captive/presenter/log_line.rb', line 17 def call(raw_line) line = raw_line.chomp first, second, = line.split(" ", 3) return line if first.nil? || second.nil? || .nil? bracket, ts = (first, second) return line unless bracket label = LogUtils::ProcessLabel.for(pod: bracket[:pod], namespace: @app, container: bracket[:container]) @colorizer.format_line(ts: ts, label: label, message: ) end |