Skip to content

Instantly share code, notes, and snippets.

@repeatedly
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save repeatedly/cb16d5667350c8a0e2c9 to your computer and use it in GitHub Desktop.
Save repeatedly/cb16d5667350c8a0e2c9 to your computer and use it in GitHub Desktop.
Filter example2: add tag and time like existence mixins
module Fluent
class AddMetadataFilter < Filter
Plugin.register_filter('add_metadata', self)
config_param :include_time_key, :bool, :default => false
config_param :time_key, :string, :default => 'time'
config_param :time_format, :string, :default => nil
config_param :include_tag_key, :bool, :default => false
config_param :tag_key, :string, :default => 'tag'
config_param :localtime, :bool, :default => true
def configure(conf)
super
if conf['utc']
@localtime = false
end
@timef = TimeFormatter.new(@time_format, @localtime)
end
def filter(tag, time, record)
if @include_tag_key
record[@tag_key] = tag
end
if @include_time_key
record[@time_key] = @timef.format(time)
end
record
end
end if defined?(Filter) # Avoid 'uninitialized constant Fluent::Filter' at Fluentd v0.10
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment