lib/dexter/log_parser.rb in pgdexter-0.3.0 vs lib/dexter/log_parser.rb in pgdexter-0.3.1

- old
+ new

@@ -1,9 +1,10 @@ module Dexter class LogParser - REGEX = /duration: (\d+\.\d+) ms (statement|execute <unnamed>|parse <unnamed>): (.+)/ + REGEX = /duration: (\d+\.\d+) ms (statement|execute <unnamed>): (.+)/ LINE_SEPERATOR = ": ".freeze + DETAIL_LINE = "DETAIL: ".freeze def initialize(logfile, collector) @logfile = logfile @collector = collector end @@ -12,11 +13,13 @@ active_line = nil duration = nil @logfile.each_line do |line| if active_line - if line.include?(LINE_SEPERATOR) + if line.include?(DETAIL_LINE) + add_parameters(active_line, line.chomp.split(DETAIL_LINE)[1]) + elsif line.include?(LINE_SEPERATOR) process_entry(active_line, duration) active_line = nil else active_line << line end @@ -32,8 +35,21 @@ private def process_entry(query, duration) @collector.add(query, duration) + end + + def add_parameters(active_line, details) + if details.start_with?("parameters: ") + params = Hash[details[12..-1].split(", ").map { |s| s.split(" = ", 2) }] + + # make sure parsing was successful + unless params.values.include?(nil) + params.each do |k, v| + active_line.sub!(k, v) + end + end + end end end end