Sha256: 0a940048bfec7f77dbcd4ac4f1a703ea5c11f02d2a7efa2d1c450806ff9f532b
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
#!/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("%<timestamp>s %<time>s %<elapsed>s %<diff>s %<lineno>s %<message>s", object) prev = timestamp rescue => e puts e.message end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ix-cli-0.0.16 | bin/ix-timestamp2 |