The formatter
plugin helper manages the lifecycle of the formatter plugin.
Here is an example:
require 'fluent/plugin/output'​module Fluent::Pluginclass ExampleOutput < OutputFluent::Plugin.register_output('example', self)​# 1. Load formatter helperhelpers :formatter​# Omit `shutdown` and other plugin APIs​def configure(conf)super​# 2. Call `formatter_create` to create object@formatter = formatter_create(usage: 'awesome_formatter')end​def format(tag, time, record)# 3. Call `format` method to format `record`@formatter.format(tag, time, record)endendend
For more details, see the following articles:
​Format Section​
usage
: unique name required for multiple formatters
type
: formatter type
conf
: formatter plugin configuration
default_type
: default formatter type
Examples:
def configure(conf)super# Create formatter plugin instance using <format> section in `fluent.conf` during configure phase@formatter = formatter_createend​def format(tag, time, record)@formatter.format(tag, time, record)end
JSON formatter example:
# Create JSON formatterdef configure(conf)super@json_formatter = formatter_create(usage: 'formatter_in_example_json', type: 'json')end​def format(tag, time, record)@json_formatter.format(tag, time, record)end
MsgPack formatter example:
# Create MsgPack formatterdef configure(conf)super@msgpack_formatter = formatter_create(usage: 'formatter_in_example_msgpack', type: 'msgpack')end​def format(tag, time, record)@msgpack_formatter.format(tag, time, record)end
​filter_stdout
​
​out_stdout
​
​out_exec
​
​out_exec_filter
​
​out_file
​
​out_s3
​
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.