Class: SyslogPGParser

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

Constant Summary collapse

CMD_LINE =
Regexp.new('\[(\d{1,10})(\-\d{1,5}){0,1}\] ')

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

#initialize(syslog_str = 'postgres') ⇒ SyslogPGParser

Returns a new instance of SyslogPGParser.



508
509
510
# File 'lib/pqa.rb', line 508

def initialize(syslog_str = 'postgres')
  @postgres_pid = Regexp.new(" " + syslog_str + '\[(\d{1,5})\]: ')
end

Instance Method Details

#parse(data) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/pqa.rb', line 512

def parse(data)
  recognized = false

  pid_match=@postgres_pid.match(data)
  return if pid_match.nil?

  connection_id = pid_match[1]
  text = pid_match.post_match
  return nil if text == nil

  line_id_match = CMD_LINE.match(text)
  return nil if line_id_match.nil?

  text = line_id_match.post_match
  cmd_no = line_id_match[1]
  if line_id_match[2]
    line_no = line_id_match[2][1..-1]
  else
    line_no = 1
  end


  result = super(text)
  return nil if result.nil?

  result.connection_id = connection_id
  result.cmd_no = cmd_no
  result.line_no = line_no 

   # $stderr.puts result.dump

  return result
end