Class: Fluent::TextParser::SyslogParser
- Defined in:
- lib/fluent/parser.rb
Constant Summary collapse
- REGEXP =
From existence TextParser pattern
/^(?<time>[^ ]*\s*[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?(?:[^\:]*\:)? *(?<message>.*)$/- REGEXP_WITH_PRI =
From in_syslog default pattern
/^\<(?<pri>[0-9]+)\>(?<time>[^ ]* {1,2}[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?(?:[^\:]*\:)? *(?<message>.*)$/
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from Parser
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ SyslogParser
constructor
A new instance of SyslogParser.
- #parse(text) ⇒ Object
- #patterns ⇒ Object
Methods inherited from Parser
Methods included from Configurable
#config, included, lookup_type, register_type
Constructor Details
#initialize ⇒ SyslogParser
Returns a new instance of SyslogParser.
542 543 544 545 |
# File 'lib/fluent/parser.rb', line 542 def initialize super @mutex = Mutex.new end |
Instance Method Details
#configure(conf) ⇒ Object
547 548 549 550 551 552 |
# File 'lib/fluent/parser.rb', line 547 def configure(conf) super @regexp = @with_priority ? REGEXP_WITH_PRI : REGEXP @time_parser = TextParser::TimeParser.new(@time_format) end |
#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 587 588 589 590 591 592 593 594 595 |
# File 'lib/fluent/parser.rb', line 558 def parse(text) m = @regexp.match(text) unless m if block_given? yield nil, nil return else return nil, nil end end time = nil record = {} m.names.each { |name| if value = m[name] case name when "pri" record['pri'] = value.to_i when "time" time = @mutex.synchronize { @time_parser.parse(value.gsub(/ +/, ' ')) } record[name] = value if @keep_time_key else record[name] = value end end } if @estimate_current_event time ||= Engine.now end if block_given? yield time, record else return time, record end end |
#patterns ⇒ Object
554 555 556 |
# File 'lib/fluent/parser.rb', line 554 def patterns {'format' => @regexp, 'time_format' => @time_format} end |