The record_accessor plugin helper provides unified access to the event record. It uses jsonpath like syntax for the target field. With this helper, you can easily access/delete a nested field in the plugin.
Here is an example:
require'fluent/plugin/filter'moduleFluent::PluginclassExampleFilter<FilterFluent::Plugin.register_filter('example', self)# 1. Load record_accessor helper helpers :record_accessordefconfigure(conf)super# 2. Call `record_accessor_create` to create object @accessor =record_accessor_create('$.user.name')end# Omit `super`, `shutdown` and other plugin APIsdeffilter(tag,time,record)# 3. Call `call` method to get value value = @accessor.call(record) # With `$.user.name`, access to record["user"]["name"]# ...endendend
Syntax
dot notation: $. is the starting parameter. Chain fields with dots ..
For example:
$.event.level for record["event"]["level"]
$.key1[0].key2 for record["key1"][0]["key2"]
bracket notation: $[ starting parameter. Chain fields with [].
Useful for special characters, ., whitespace, etc.
$['dot.key'][0]['space key'] for record["dot.key"][0]["space key"]
If you set non $. or $[ starting value, e.g. key log, it is the same as record["log"]. So, using record_accessor does not break the existing plugin behavior.
Methods
record_accessor_create(param)
This method returns the accessor object of the event record.
The param is a String.
See the "Syntax" section for more details.
After creating an object, call call/delete/set method with the record object.