Sha256: c4d7ee09da90a87f844c9337cce224a1dbbefe5674719e3b5340112403aa9674

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

module Dexter
  class LogParser
    include Logging

    REGEX = /duration: (\d+\.\d+) ms  (statement|execute [^:]+): (.+)/
    LINE_SEPERATOR = ":  ".freeze
    DETAIL_LINE = "DETAIL:  ".freeze

    attr_accessor :once

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

    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pgdexter-0.4.3 lib/dexter/log_parser.rb