Class: Dexter::LogParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dexter/log_parser.rb

Constant Summary collapse

REGEX =
/duration: (\d+\.\d+) ms  (statement|execute <unnamed>): (.+)/
LINE_SEPERATOR =
":  ".freeze

Instance Method Summary collapse

Constructor Details

#initialize(logfile, collector) ⇒ LogParser

Returns a new instance of LogParser.



6
7
8
9
# File 'lib/dexter/log_parser.rb', line 6

def initialize(logfile, collector)
  @logfile = logfile
  @collector = collector
end

Instance Method Details

#performObject



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

def perform
  active_line = nil
  duration = nil

  each_line do |line|
    if active_line
      if line.include?(LINE_SEPERATOR)
        process_entry(active_line, duration)
        active_line = nil
      else
        active_line << line
      end
    end

    if !active_line && m = REGEX.match(line.chomp)
      duration = m[1].to_f
      active_line = m[3]
    end
  end
  process_entry(active_line, duration) if active_line
end