Class: Captive::Presenter::LogColorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/captive/presenter/log_colorizer.rb

Overview

Renders a log line as a colorized terminal string using Pastel and LogUtils.

Constant Summary collapse

TIME_FORMAT =
"%Y-%m-%d %H:%M:%S.%N %z %Z"
PASTEL_COLORS =
{
  "blue"    => :blue,
  "green"   => :green,
  "yellow"  => :yellow,
  "red"     => :red,
  "magenta" => :magenta,
  "dim"     => :bright_black,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(paint: Pastel.new, stripper: AnsiStripper.new) ⇒ LogColorizer

Returns a new instance of LogColorizer.



23
24
25
26
# File 'lib/captive/presenter/log_colorizer.rb', line 23

def initialize(paint: Pastel.new, stripper: AnsiStripper.new)
  @paint = paint
  @stripper = stripper
end

Instance Method Details

#format_line(ts:, label:, message:) ⇒ Object



28
29
30
# File 'lib/captive/presenter/log_colorizer.rb', line 28

def format_line(ts:, label:, message:)
  "#{dim_time(ts)} #{badge(label)} #{colorize_message(message)}"
end