Module: Fluent::Compat::HandleTagAndTimeMixin

Defined in:
lib/fluent/compat/handle_tag_and_time_mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fluent/compat/handle_tag_and_time_mixin.rb', line 22

def self.included(klass)
  klass.instance_eval {
    config_param :include_time_key, :bool, default: false
    config_param :time_key, :string, default: 'time'
    config_param :time_format, :string, default: nil
    config_param :time_as_epoch, :bool, default: false
    config_param :include_tag_key, :bool, default: false
    config_param :tag_key, :string, default: 'tag'
    config_param :localtime, :bool, default: true
    config_param :timezone, :string, default: nil
  }
end

Instance Method Details

#configure(conf) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fluent/compat/handle_tag_and_time_mixin.rb', line 35

def configure(conf)
  super

  if conf['utc']
    @localtime = false
  end
  @timef = Fluent::TimeFormatter.new(@time_format, @localtime, @timezone)
  if @time_as_epoch && !@include_time_key
    log.warn "time_as_epoch will be ignored because include_time_key is false"
  end
end

#filter_record(tag, time, record) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fluent/compat/handle_tag_and_time_mixin.rb', line 47

def filter_record(tag, time, record)
  if @include_tag_key
    record[@tag_key] = tag
  end
  if @include_time_key
    if @time_as_epoch
      record[@time_key] = time.to_i
    else
      record[@time_key] = @timef.format(time)
    end
  end
end