Class: Fluent::TextParser::RegexpParser
- Includes:
- TypeConverter
- Defined in:
- lib/fluent/parser.rb
Constant Summary
Constants included from TypeConverter
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from Parser
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize(regexp, conf = {}) ⇒ RegexpParser
constructor
A new instance of RegexpParser.
- #parse(text) ⇒ Object
- #patterns ⇒ Object
Methods included from TypeConverter
Methods inherited from Parser
Methods included from Configurable
#config, included, lookup_type, register_type
Constructor Details
#initialize(regexp, conf = {}) ⇒ RegexpParser
Returns a new instance of RegexpParser.
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/fluent/parser.rb', line 178 def initialize(regexp, conf={}) super() @regexp = regexp unless conf.empty? conf = Config::Element.new('default_regexp_conf', '', conf, []) unless conf.is_a?(Config::Element) configure(conf) end @time_parser = TimeParser.new(@time_format) @mutex = Mutex.new end |
Instance Method Details
#configure(conf) ⇒ Object
190 191 192 193 |
# File 'lib/fluent/parser.rb', line 190 def configure(conf) super @time_parser = TimeParser.new(@time_format) end |
#parse(text) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/fluent/parser.rb', line 199 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 @time_key time = @mutex.synchronize { @time_parser.parse(value) } if @keep_time_key record[name] = if @type_converters.nil? value else convert_type(name, value) end end else record[name] = if @type_converters.nil? value else convert_type(name, value) end end end } if @estimate_current_event time ||= Engine.now end if block_given? yield time, record else # keep backward compatibility. will be removed at v1 return time, record end end |
#patterns ⇒ Object
195 196 197 |
# File 'lib/fluent/parser.rb', line 195 def patterns {'format' => @regexp, 'time_format' => @time_format} end |