Method: UPM::LogParser#log_events

Defined in:
lib/upm/log_parser.rb

#log_eventsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/upm/log_parser.rb', line 9

def log_events
  return to_enum(:log_events) unless block_given?

  yielder = proc do |io|
    io.each_line do |line|
      if e = @klass.from_line(line.strip)
        yield e
      end
    end
  end

  logs = Dir[@log_glob].sort_by { |path| File.mtime(path) } 

  logs.each do |log|
    if log =~ /\.gz$/
      IO.popen(["zcat", log], &yielder)
    else
      open(log, &yielder)
    end 
  end
end