Class: LogMerge
- Inherits:
-
Object
- Object
- LogMerge
- Defined in:
- lib/logmerge.rb
Instance Attribute Summary collapse
-
#endTime ⇒ Object
readonly
Returns the value of attribute endTime.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#startTime ⇒ Object
readonly
Returns the value of attribute startTime.
Instance Method Summary collapse
- #applyColor(loglines, color) ⇒ Object
-
#initialize(files, startTime = Time.at(0), endTime = Time.at(2000000000000), autotag = false) ⇒ LogMerge
constructor
A new instance of LogMerge.
- #merge ⇒ Object
Constructor Details
#initialize(files, startTime = Time.at(0), endTime = Time.at(2000000000000), autotag = false) ⇒ LogMerge
Returns a new instance of LogMerge.
132 133 134 135 136 |
# 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 |
Instance Attribute Details
#endTime ⇒ Object (readonly)
Returns the value of attribute endTime.
131 132 133 |
# File 'lib/logmerge.rb', line 131 def endTime @endTime end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
131 132 133 |
# File 'lib/logmerge.rb', line 131 def logs @logs end |
#startTime ⇒ Object (readonly)
Returns the value of attribute startTime.
131 132 133 |
# File 'lib/logmerge.rb', line 131 def startTime @startTime end |
Instance Method Details
#applyColor(loglines, color) ⇒ Object
156 157 158 |
# File 'lib/logmerge.rb', line 156 def applyColor(loglines, color) loglines.map{|l| Colored.colorize(l, foreground: color)} end |
#merge ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# 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. && b. ? a. <=> b. : b. ? -1 : 1 }.first #could be priority queue instead break if min_log.nil? next min_log.take unless min_log. next min_log.take if min_log. < startTime break if min_log.nil? break if min_log. > 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 |