Class: Fluent::ElasticsearchOutput::TimeParser
- Inherits:
-
Object
- Object
- Fluent::ElasticsearchOutput::TimeParser
- Defined in:
- lib/fluent/plugin/out_elasticsearch.rb
Overview
once fluent v0.14 is released we might be able to use Fluent::Parser::TimeParser, but it doesn’t quite do what we want - if gives
- sec,nsec
-
where as we want something we can call ‘strftime` on…
Instance Method Summary collapse
-
#initialize(time_key_format, router) ⇒ TimeParser
constructor
A new instance of TimeParser.
- #parse(value, event_time) ⇒ Object
Constructor Details
#initialize(time_key_format, router) ⇒ TimeParser
Returns a new instance of TimeParser.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/fluent/plugin/out_elasticsearch.rb', line 100 def initialize(time_key_format, router) @time_key_format = time_key_format @router = router @parser = if time_key_format begin # Strptime doesn't support all formats, but for those it does it's # blazingly fast. strptime = Strptime.new(time_key_format) Proc.new { |value| strptime.exec(value).to_datetime } rescue # Can happen if Strptime doesn't recognize the format; or # if strptime couldn't be required (because it's not installed -- it's # ruby 2 only) Proc.new { |value| DateTime.strptime(value, time_key_format) } end else Proc.new { |value| DateTime.parse(value) } end end |
Instance Method Details
#parse(value, event_time) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/fluent/plugin/out_elasticsearch.rb', line 120 def parse(value, event_time) @parser.call(value) rescue => e @router.emit_error_event("Fluent::ElasticsearchOutput::TimeParser.error", Fluent::Engine.now, {'time' => event_time, 'format' => @time_key_format, 'value' => value }, e) return Time.at(event_time).to_datetime end |