Class: PostgresLogParser

Inherits:
PostgreSQLParser show all
Defined in:
lib/pqa.rb

Constant Summary collapse

STARTS_WITH_DATE =
Regexp.new("^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ")
STARTS_WITH_PID =
Regexp.new('\[(\d{1,5})\] ')

Constants inherited from PostgreSQLParser

PostgreSQLParser::CONTEXT_LINE, PostgreSQLParser::CONTINUATION_LINE, PostgreSQLParser::DETAIL_LINE, PostgreSQLParser::DURATION, PostgreSQLParser::ERROR_LINE, PostgreSQLParser::HINT_LINE, PostgreSQLParser::LOG_OR_DEBUG_LINE, PostgreSQLParser::QUERY_STARTER, PostgreSQLParser::STATEMENT_LINE, PostgreSQLParser::STATUS

Instance Method Summary collapse

Constructor Details

#initializePostgresLogParser

Returns a new instance of PostgresLogParser.



553
554
555
556
# File 'lib/pqa.rb', line 553

def initialize
  @conn_id_found = false
  @last_conn_id = nil
end

Instance Method Details

#parse(text) ⇒ Object



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/pqa.rb', line 558

def parse(text)  
  connection_id = nil
  text = STARTS_WITH_DATE.match(text) ? text.split(" ")[2..-1].join(" ").strip : text

  pid_match = STARTS_WITH_PID.match(text)
  if pid_match
    @conn_id_found = true
    connection_id = pid_match[1]
    @last_conn_id = connection_id
    text = pid_match.post_match.strip
  end
  
  result = super(text)
  # Badly formated continuations need this...
  #if result.nil?
  #  result = PGContinuationLine.new(text)
  #end
  return nil if result.nil?

  if pid_match
    result.connection_id = connection_id
  else
    result.connection_id = @last_conn_id
  end

  # $stderr.puts result.dump

  return result
end