This page is for v0.14, not the latest stable version which is v0.12. For the latest stable version of this article, click here.
Writing Filter Plugins
This section shows how to write custom filters in addition to the core filter plugins. The plugin files whose names start with “filter_” are registered as filter plugins. See Plugin Base Class API to show details of common API for all plugin types.
Here is the implementation of the most basic filter that passes through all events as-is:
require 'fluent/plugin/filter' module Fluent::Plugin class PassThruFilter < Filter # Register this filter as "passthru" Fluent::Plugin.register_filter('passthru', self) # config_param works like other plugins def configure(conf) super # do the usual configuration here end # def start # super # # Override this method if anything needed as startup. # end # def shutdown # # Override this method to use it to free up resources, etc. # super # end def filter(tag, time, record) # Since our example is a pass-thru filter, it does nothing and just # returns the record as-is. # If returns nil, that records are ignored. record end end end
Table of Contents
Filter plugins have a method to be implemented.
#filter(tag, time, record)
This method implements the filtering logic for individual filters.
tag is a String,
time is a Fluent::EventTime or an Integer and
record is a Hash with String keys.
The return value of this method should be a Hash of modified record, or nil. Fluentd will ignore the event which the filter returns nil.
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is a open source project under Cloud Native Computing Foundation (CNCF), originally invented by Treasure Data, Inc. All components are available under the Apache 2 License.