Class: FluentExt::TextParser::GenericParser
- Inherits:
-
Object
- Object
- FluentExt::TextParser::GenericParser
- Includes:
- Fluent::Configurable
- Defined in:
- lib/fluent/plugin/fixed_parser.rb
Direct Known Subclasses
ApacheParser, JSONParser, LabeledTSVParser, RegexpParser, ValuesParser
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize ⇒ GenericParser
constructor
A new instance of GenericParser.
- #parse_time(record) ⇒ Object
Constructor Details
#initialize ⇒ GenericParser
Returns a new instance of GenericParser.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fluent/plugin/fixed_parser.rb', line 16 def initialize super @cache1_key = nil @cache1_time = nil @cache2_key = nil @cache2_time = nil @log = nil end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
14 15 16 |
# File 'lib/fluent/plugin/fixed_parser.rb', line 14 def log @log end |
Instance Method Details
#parse_time(record) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fluent/plugin/fixed_parser.rb', line 27 def parse_time(record) time = nil unless @time_parse return time, record end if value = record.delete(@time_key) if @cache1_key == value time = @cache1_time elsif @cache2_key == value time = @cache2_time else begin time = if @time_format Time.strptime(value, @time_format).to_i else Time.parse(value).to_i end @cache1_key = @cache2_key @cache1_time = @cache2_time @cache2_key = value @cache2_time = time rescue TypeError, ArgumentError => e @log.warn "Failed to parse time", :key => @time_key, :value => value record[@time_key] = value end end end return time, record end |