Last active
August 29, 2015 14:05
-
-
Save repeatedly/cb16d5667350c8a0e2c9 to your computer and use it in GitHub Desktop.
Filter example2: add tag and time like existence mixins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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