class Azuki::Helpers::LogDisplayer
Constants
- COLORS
- COLOR_CODES
Attributes
app[R]
azuki[R]
opts[R]
Public Class Methods
new(azuki, app, opts)
click to toggle source
# File lib/azuki/helpers/log_displayer.rb, line 10 def initialize(azuki, app, opts) @azuki, @app, @opts = azuki, app, opts end
Public Instance Methods
colorize(chunk)
click to toggle source
# File lib/azuki/helpers/log_displayer.rb, line 45 def colorize(chunk) lines = [] chunk.split("\n").map do |line| if parsed_line = parse_log(line) header, identifier, body = parsed_line @assigned_colors[identifier] ||= COLORS[@assigned_colors.size % COLORS.size] lines << [ "\e[#{COLOR_CODES[@assigned_colors[identifier]]}m", header, "\e[0m", body, ].join("") elsif not line.empty? lines << line end end lines.join("\n") end
display_logs()
click to toggle source
# File lib/azuki/helpers/log_displayer.rb, line 14 def display_logs @assigned_colors = {} @line_start = true @token = nil azuki.read_logs(app, opts) do |chunk| unless chunk.empty? if STDOUT.isatty && ENV.has_key?("TERM") display(colorize(chunk)) else display(chunk) end end end rescue Errno::EPIPE rescue Interrupt => interrupt if STDOUT.isatty && ENV.has_key?("TERM") display("\e[0m") end raise(interrupt) end
parse_log(log)
click to toggle source
# File lib/azuki/helpers/log_displayer.rb, line 64 def parse_log(log) return unless parsed = log.match(/^(.*?\[(\w+)([\d\.]+)?\]:)(.*)?$/) [1, 2, 4].map { |i| parsed[i] } end