Class: Fluent::Plugin::SyslogParser
- Defined in:
- lib/fluent/plugin/parser_syslog.rb
Direct Known Subclasses
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 inherited from Parser
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from Parser
Attributes inherited from Base
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ SyslogParser
constructor
A new instance of SyslogParser.
- #parse(text) {|time, record| ... } ⇒ Object
- #patterns ⇒ Object
Methods inherited from Parser
Methods included from TimeMixin::Parser
Methods included from OwnedByMixin
Methods inherited from Base
#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #has_router?, #inspect, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #terminate, #terminated?
Methods included from SystemConfig::Mixin
#system_config, #system_config_override
Methods included from Configurable
#config, included, lookup_type, register_type
Constructor Details
#initialize ⇒ SyslogParser
Returns a new instance of SyslogParser.
34 35 36 37 |
# File 'lib/fluent/plugin/parser_syslog.rb', line 34 def initialize super @mutex = Mutex.new end |
Instance Method Details
#configure(conf) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/fluent/plugin/parser_syslog.rb', line 39 def configure(conf) super @regexp = @with_priority ? REGEXP_WITH_PRI : REGEXP @time_parser = time_parser_create end |
#parse(text) {|time, record| ... } ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fluent/plugin/parser_syslog.rb', line 50 def parse(text) m = @regexp.match(text) unless m yield nil, nil return 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 ||= Fluent::EventTime.now end yield time, record end |
#patterns ⇒ Object
46 47 48 |
# File 'lib/fluent/plugin/parser_syslog.rb', line 46 def patterns {'format' => @regexp, 'time_format' => @time_format} end |