$ cd build/
$ cmake -DFLB_DEBUG=On -DFLB_PROXY_GO=On ../
$ make
编译后,我们可以在二进制中看到新选项 -e,它代表扩展插件,例如:
$ bin/fluent-bit -h
Usage: fluent-bit [OPTION]
Available Options
-c --config=FILE specify an optional configuration file, 指定可选的配置文件
-d, --daemon run Fluent Bit in background mode, 以后台方式运行 Fluent Bit
-f, --flush=SECONDS flush timeout in seconds (default: 5), 刷新数据到输出的超时时间(默认 5 秒)
-i, --input=INPUT set an input, 设置输入
-m, --match=MATCH set plugin match, same as '-p match=abc', 设置插件匹配的标签模式,与 '-p match=abc' 相同
-o, --output=OUTPUT set an output, 设置输出
-p, --prop="A=B" set plugin configuration property, 设置插件配置参数
-e, --plugin=FILE load an external plugin (shared lib), 加载扩展插件(共享库)
...
packagemainimport"github.com/fluent/fluent-bit-go/output"//export FLBPluginRegisterfuncFLBPluginRegister(def unsafe.Pointer) int {// Gets called only once when the plugin.so is loadedreturn output.FLBPluginRegister(ctx, "gstdout", "Stdout GO!")}//export FLBPluginInitfuncFLBPluginInit(plugin unsafe.Pointer) int {// Gets called only once for each instance you have configured.return output.FLB_OK}//export FLBPluginFlushCtxfuncFLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int {// Gets called with a batch of records to be written to an instance.return output.FLB_OK}//export FLBPluginExitfuncFLBPluginExit() int {return output.FLB_OK}funcmain() {}
上面的代码是编写输出插件的模板,将包名称设置为 main 并添加显式的 main() 函数非常重要。这是必需的,因为代码将被构建为共享库。