Module: Fluent::SetTimeKeyMixin

Includes:
RecordFilterMixin
Defined in:
lib/fluent/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.



129
130
131
# File 'lib/fluent/mixin.rb', line 129

def include_time_key
  @include_time_key
end

#localtimeObject

Returns the value of attribute localtime.



129
130
131
# File 'lib/fluent/mixin.rb', line 129

def localtime
  @localtime
end

#time_keyObject

Returns the value of attribute time_key.



129
130
131
# File 'lib/fluent/mixin.rb', line 129

def time_key
  @time_key
end

#timezoneObject

Returns the value of attribute timezone.



129
130
131
# File 'lib/fluent/mixin.rb', line 129

def timezone
  @timezone
end

Instance Method Details

#configure(conf) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/fluent/mixin.rb', line 131

def configure(conf)
  @include_time_key = false

  super

  if s = conf['include_time_key']
    include_time_key = Config.bool_value(s)
    raise 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 = TimeFormatter.new(@time_format, @localtime, @timezone)
  end
end

#filter_record(tag, time, record) ⇒ Object



162
163
164
165
166
# File 'lib/fluent/mixin.rb', line 162

def filter_record(tag, time, record)
  super

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