#!/usr/bin/env ruby require 'json' require 'isna' start = false prev = false lineno = 0 colors = true STDIN.each_line do |line| begin lineno += 1 json = JSON.parse(line) timestamp = json['timestamp'].to_f unless start start = timestamp prev = timestamp end object = { :timestamp => timestamp.to_s.rjust(20, ' '), :time => Time.at(timestamp).to_s.rjust(20, ' '), :elapsed => format('%1.5f', (timestamp - start)).to_s.rjust(10, ' '), :diff => format('%2.5f', (timestamp - prev)).to_s.rjust(10, ' '), :lineno => (('| ') + (lineno.to_s)).ljust(5, ' '), :message => json['message'] } if colors object[:timestamp] = object[:timestamp].to_s.to_ansi.yellow.to_s object[:time] = object[:time].to_s.to_ansi.cyan.to_s object[:elapsed] = object[:elapsed].to_s.to_ansi.pink.to_s if (timestamp - prev) > 1 and (timestamp - prev) < 10 object[:diff] = object[:diff].to_s.to_ansi.green.to_s end if (timestamp - prev) > 10 and (timestamp - prev) < 50 object[:diff] = object[:diff].to_s.to_ansi.yellow.to_s end if (timestamp - prev) > 50 object[:diff] = object[:diff].to_s.to_ansi.red.to_s end object[:lineno] = object[:lineno].to_s.to_ansi.cyan.to_s end puts format("%s %