class LogMerge
Attributes
endTime[R]
logs[R]
startTime[R]
Public Class Methods
new(files, startTime=Time.at(0), endTime=Time.at(2000000000000), autotag=false)
click to toggle source
# File lib/logmerge.rb, line 132 def initialize(files, startTime=Time.at(0), endTime=Time.at(2000000000000), autotag=false) @logs = files.map {|f| Log.new(f, autotag)} @startTime = DateTime.parse(startTime.to_s) @endTime = DateTime.parse(endTime.to_s) end
Public Instance Methods
applyColor(loglines, color)
click to toggle source
# File lib/logmerge.rb, line 156 def applyColor(loglines, color) loglines.map{|l| Colored.colorize(l, foreground: color)} end
merge()
click to toggle source
# File lib/logmerge.rb, line 138 def merge colors = Colored::COLORS.keys.dup colors.delete('black') while true min_log = logs.select {|l| !l.finished}.sort { |a,b| a.timestamp && b.timestamp ? a.timestamp <=> b.timestamp : b.timestamp ? -1 : 1 }.first #could be priority queue instead break if min_log.nil? next min_log.take unless min_log.timestamp next min_log.take if min_log.timestamp < startTime break if min_log.nil? break if min_log.timestamp > endTime index = logs.index(min_log) color_index = index % colors.size color = colors[color_index] loglines = min_log.take puts applyColor(loglines, color).join("\n") end end