Sha256: 67d386d2d14d62a1f20e8ab83c2ac6e1744735084321b658b8add4c907623760

Contents?: true

Size: 1.91 KB

Versions: 292

Compression:

Stored size: 1.91 KB

Contents

#
# Fluentd
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

require 'fluent/config/error'
require 'fluent/compat/record_filter_mixin'
require 'fluent/time'
require 'fluent/timezone'

module Fluent
  module Compat
    module SetTimeKeyMixin
      include RecordFilterMixin

      attr_accessor :include_time_key, :time_key, :localtime, :timezone

      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

      def filter_record(tag, time, record)
        super

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

Version data entries

292 entries across 292 versions & 8 rubygems

Version Path
fluentd-1.16.0 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.3-x86-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.3-x64-mingw-ucrt lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.3-x64-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.3 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.2-x86-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.2-x64-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.2-x64-mingw-ucrt lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.2 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.1-x86-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.1-x64-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.1-x64-mingw-ucrt lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.1 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.0-x86-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.0-x64-mingw-ucrt lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.0-x64-mingw32 lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.15.0 lib/fluent/compat/set_time_key_mixin.rb
dtomasgu-fluentd-1.14.8.pre.dev lib/fluent/compat/set_time_key_mixin.rb
dtomasgu-fluentd-1.14.7.pre.dev lib/fluent/compat/set_time_key_mixin.rb
fluentd-1.14.6-x86-mingw32 lib/fluent/compat/set_time_key_mixin.rb