Multiline
Concatenate multiline or stack trace log messages.
The Multiline filter helps concatenate messages that originally belonged to one context but were split across multiple records or log lines. Common examples are stack traces or applications that print logs in multiple lines.
Along with multiline filters, you can enable one of the following built-in Fluent Bit parsers with auto-detection and multi-format support:
Go
Python
Ruby
Java (Google Cloud Platform Java stack trace format)
When using this filter:
The usage of this filter depends on a previous configuration of a multiline parser definition.
To concatenate messages read from a log file, it's highly recommended to use the multiline support in the Tail plugin itself. This is because performing concatenation while reading the log file is more performant. Concatenating messages that were originally one line, but split by Docker or CRI container engines because of their size, is supported in the Tail plugin in combination with the
dockerorcriparser. To concatenate application logs like stacktraces on top of that, you can use this multiline filter.
This filter only performs buffering that persists across different Chunks when Buffer is enabled. Otherwise, the filter processes one chunk at a time and isn't suitable for most inputs which might send multiline messages in separate chunks.
When buffering is enabled, the filter doesn't immediately emit messages it receives. It uses the in_emitter plugin, similar to the Rewrite Tag filter, and emits messages once they're fully concatenated, or a timeout is reached.
Since concatenated records are re-emitted to the head of the Fluent Bit log pipeline, you can not configure multiple multiline filter definitions that match the same tags. This will cause an infinite loop in the Fluent Bit pipeline; to use multiple parsers on the same logs, configure a single filter definitions with a comma separated list of parsers for multiline.parser. For more, see issue #5235.
Secondly, for the same reason, the multiline filter should be the first filter. Logs will be re-emitted by the multiline filter to the head of the pipeline - the filter will ignore its own re-emitted records, but other filters won't. If there are filters before the multiline filter, they will be applied twice.
Configuration parameters
The plugin supports the following configuration parameters:
multiline.parser
Specify one or multiple Multiline Parser definitions to apply to the content. You can specify multiple multiline parsers to detect different formats by separating them with a comma.
multiline.key_content
Key name that holds the content to process. A multiline parser definition can specify the key_content This option allows for overwriting that value for the purpose of the filter.
mode
Mode can be parser for regular expression concatenation, or partial_message to concatenate split Docker logs.
buffer
Enable buffered mode. In buffered mode, the filter can concatenate multiple lines from inputs that ingest records one by one (like Forward), rather than in chunks, re-emitting them into the beginning of the pipeline (with the same tag) using the in_emitter instance. With buffer off, this filter won't work with most inputs, except Tail.
flush_ms
Flush time for pending multiline records. Default: 2000.
emitter_name
Name for the emitter input instance which re-emits the completed records at the beginning of the pipeline.
emitter_storage.type
The storage type for the emitter input instance. This option supports the values memory (default) and filesystem.
emitter_mem_buf_limit
Set a limit on the amount of memory the emitter can consume if the outputs provide backpressure. The default for this limit is 10M. The pipeline will pause once the buffer exceeds the value of this setting. or example, if the value is set to 10M then the pipeline pauses if the buffer exceeds 10M. The pipeline will remain paused until the output drains the buffer under the 10M limit.
Configuration example
The following example aims to parse a log file called test.log that contains some full lines, a custom Java stack trace and a Go Stack Trace.
The following example files can be located in the Fluent Bit repository.
Example files content:
This is the primary Fluent Bit YAML configuration file. It includes the parsers_multiline.yaml and tails the file test.log by applying the multiline parsers multiline-regex-test and go. Then it sends the processing to the standard output.
This is the primary Fluent Bit classic configuration file. It includes the parsers_multiline.conf and tails the file test.log by applying the multiline parsers multiline-regex-test and go. Then it sends the processing to the standard output.
This file defines a multiline parser for the example. A second multiline parser called go is used in fluent-bit.yaml, but this one is a built-in parser.
This file defines a multiline parser for the example. A second multiline parser called go is used in fluent-bit.conf, but this one is a built-in parser.
An example file with multiline and multi-format content:
Running Fluent Bit with the given configuration file:
Should return something like the following:
Lines that don't match a pattern aren't considered as part of the multiline message, while the ones that matched the rules were concatenated properly.
Docker partial message use case
When Fluent Bit is consuming logs from a container runtime, such as Docker, these logs will be split when larger than a certain limit, usually 16 KB. If your application emits a 100K log line, it will be split into seven partial messages. The docker parser will merge these back to one line. If instead you are using the Fluentd Docker Log Driver to send the logs to Fluent Bit, they might look like this:
Fluent Bit can re-combine these logs that were split by the runtime and remove the partial message fields. The following filter example is for this use case.
The two options for mode are mutually exclusive in the filter. If you set the mode to partial_message then the multiline.parser option isn't allowed.
Last updated
Was this helpful?