Module: Fluent::Compat::SetTimeKeyMixin

Includes:
RecordFilterMixin
Defined in:
lib/fluent/compat/set_time_key_mixin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RecordFilterMixin

#format_stream

Instance Attribute Details

#include_time_keyObject

Returns the value of attribute include_time_key.



27
28
29
# File 'lib/fluent/compat/set_time_key_mixin.rb', line 27

def include_time_key
  @include_time_key
end

#localtimeObject

Returns the value of attribute localtime.



27
28
29
# File 'lib/fluent/compat/set_time_key_mixin.rb', line 27

def localtime
  @localtime
end

#time_keyObject

Returns the value of attribute time_key.



27
28
29
# File 'lib/fluent/compat/set_time_key_mixin.rb', line 27

def time_key
  @time_key
end

#timezoneObject

Returns the value of attribute timezone.



27
28
29
# File 'lib/fluent/compat/set_time_key_mixin.rb', line 27

def timezone
  @timezone
end

Instance Method Details

#configure(conf) ⇒ Object



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
59
60
# File 'lib/fluent/compat/set_time_key_mixin.rb', line 29

def configure(conf)
  @include_time_key = false
  @localtime = false
  @timezone = nil

  super

  if s = conf['include_time_key']
    include_time_key = Fluent::Config.bool_value(s)
    raise Fluent::ConfigError, "Invalid boolean expression '#{s}' for include_time_key parameter" if include_time_key.nil?

    @include_time_key = include_time_key
  end

  if @include_time_key
    @time_key     = conf['time_key'] || 'time'
    @time_format  = conf['time_format']

    if    conf['localtime']
      @localtime = true
    elsif conf['utc']
      @localtime = false
    end

    if conf['timezone']
      @timezone = conf['timezone']
      Fluent::Timezone.validate!(@timezone)
    end

    @timef = Fluent::TimeFormatter.new(@time_format, @localtime, @timezone)
  end
end

#filter_record(tag, time, record) ⇒ Object



62
63
64
65
66
# File 'lib/fluent/compat/set_time_key_mixin.rb', line 62

def filter_record(tag, time, record)
  super

  record[@time_key] = @timef.format(time) if @include_time_key
end