File
The File output plugin lets you write the data received through the input plugin to file.
Configuration parameters
enable_strftime
Enable strftime placeholders in path and file. Disabled by default so that literal percent (%) characters in existing filenames are preserved.
false
fallback_file
Static filename used when a fallback action is applied. Required whenever path or file uses a record accessor or a strftime placeholder. See Dynamic destinations.
none
fallback_path
Static directory path used together with fallback_file when a fallback action is applied.
none
file
Set filename to store the records. If not set, the filename will be the tag associated with the records. Supports record accessor expressions. When enable_strftime is true, strftime placeholders are expanded using the UTC event timestamp.
none
max_dynamic_files
Maximum number of distinct destinations that record accessor expressions and strftime placeholders can resolve to. Tag-derived filenames count when path is dynamic, or, in v5.2 or later, when path isn't dynamic, file isn't set, and this key is set explicitly. Set to 0 for unlimited. See Destination limits.
1024
mkdir
Recursively create output directory if it doesn't exist. Permissions set to 0755.
false
on_limit_reached
Action to take for a record whose destination would exceed max_dynamic_files. Accepted values: error, drop, fallback.
error
on_missing_field
Action to take for a record whose record accessor field is missing, or resolves to an unsafe value. Accepted values: error, drop, fallback.
error
path
Directory path to store files. If not set, Fluent Bit will write the files in its own working directory. Supports record accessor expressions, which must follow a static prefix. When enable_strftime is true, strftime placeholders are expanded using the UTC event timestamp.
none
rotate
Enable size-based log rotation. When enabled, files that exceed rotate_max_size are rotated and optionally compressed.
false
rotate_gzip
Compress rotated files using gzip. Only applies when rotate is enabled.
true
rotate_max_files
Maximum number of rotated files to retain per output file. Oldest files are deleted first. Must be 1 or greater. Only applies when rotate is enabled.
7
rotate_max_size
Maximum size of the active output file before rotation is triggered. Supports size suffixes: k (kilobytes), m (megabytes), g (gigabytes). Only applies when rotate is enabled.
100M
Format
This plugin uses the following formats:
out_file
Output time, tag, and json records. There are no configuration parameters for out_file.
In v5.2 or later, spaces, control characters, and the percent (%) character in the tag are written as % followed by two uppercase hexadecimal digits, so the tag is always one field without whitespace. For example, the tag app logs is written as app%20logs.
Plain
Output the records as JSON (without additional tag and timestamp attributes). There are no configuration parameters for plain format.
CSV
Output the records in CSV format. CSV mode supports additional configuration parameters.
csv_column_names
Add column names (keys) as the first line of the output file.
false
delimiter
The character to separate each field. Accepted values: \t (or tab), space, or comma. Other values, including a literal space, comma, or tab character, are ignored and fall back to the default.
,
The time field is written as seconds and nanoseconds, for example 1564462620.000254000. Strings and binary values are enclosed in double quotes. In binary values, control characters and bytes 0x7F and greater are written as \x followed by two lowercase hexadecimal digits. Numbers, booleans, and nil aren't quoted, and floating-point numbers are written with six decimal places. Line breaks inside strings aren't escaped, so a quoted field can span several lines.
In v5.2 or later, each double quote inside a value is written as two double quotes, as in RFC 4180, and arrays, maps, and extension values are also enclosed in double quotes. Strings nested in arrays and maps appear with doubled quotes, for example "[""a"", 1]". Extension values are written as (ext: <type>) followed by every data byte as \x and two lowercase hexadecimal digits.
When csv_column_names is true, Fluent Bit writes a header line starting with timestamp, followed by the quoted keys of the first record, when the file is empty, including a new file created by log rotation. Fluent Bit writes each record's values in that record's own key order and doesn't align them with the header, so records with different keys or a different key order produce misaligned columns. Make sure every record written to the same file has the same keys in the same order.
LTSV
Output the records in LTSV format. LTSV mode supports additional configuration parameters.
delimiter
The character to separate each pair. Accepted values: \t (or tab), space, or comma. Other values are ignored and fall back to the default.
\t
label_delimiter
The character to separate label and the value. Accepted values: \t (or tab), space, or comma. Other values are ignored and fall back to the default.
:
Each line starts with a time label set to the event time in seconds with six decimal places. String labels and values are enclosed in double quotes, and a double quote inside a string isn't escaped. In v5.2 or later, control characters, the percent (%) character, and any character used as delimiter or label_delimiter in a label or value are written as % followed by two uppercase hexadecimal digits. For example, with the default delimiters, the value a:b is written as "a%3Ab". Bytes 0x80 and greater in binary values are encoded the same way.
Template
Output the records using a custom format template.
template
The format string.
{time} {message}
This accepts a formatting template and fills placeholders using corresponding values in a record.
For example, if you set up the configuration like the following:
You will get the following output:
Log rotation
The File output plugin supports size-based log rotation.
When rotate is enabled, the plugin monitors the size of each output file. Once a file exceeds rotate_max_size, the next flush rotates the file by renaming it with a timestamp suffix in the format <filename>.<YYYYMMDD_HHMMSS_XXXXXXXX>. The YYYYMMDD_HHMMSS is the machine-local timestamp of the rotation, and XXXXXXXX is a random hex identifier that guarantees unique filenames if multiple rotations happen within the same second.
If rotate_gzip is enabled (the default), rotated files are compressed with gzip and stored with an additional .gz extension (for example, cpu.log.20260512_134500_a1b2c3d4.gz).
The plugin retains up to rotate_max_files rotated files per output file. When the limit is reached, the oldest rotated files are deleted automatically.
Log rotation works with all supported output formats: default (out_file), plain, csv, ltsv, template, and msgpack. File operations are thread-safe, so rotation can be used alongside multiple workers.
Log rotation example
The following configuration writes CPU metrics to file with rotation enabled. Files are rotated at 50 MB and the five most recent rotated files are retained with gzip compression:
Dynamic destinations
Dynamic destinations are available in Fluent Bit version 5.1 and greater.
The path and file parameters accept record accessor expressions, which lets one output instance write records to different files based on the content of each record. They also accept strftime placeholders, which route records by the time at which each event occurred. Fluent Bit treats a destination as dynamic when path or file contains a $ character, or when enable_strftime is true and path or file contains a percent (%) character.
Two rules apply when you configure a dynamic destination:
A
paththat uses a record accessor must begin with a static prefix. Fluent Bit rejects apaththat starts with a record accessor, so that generated paths always stay under a directory you chose. This check doesn't apply tostrftimeplaceholders. Seestrftimeplaceholders.You must set
fallback_file. Fluent Bit fails to start if a record accessor or astrftimeplaceholder is used without it, because there would be nowhere to write records whose destination can't be resolved.
Fluent Bit rejects a resolved destination as unsafe when the filename is empty, is . or .., or contains a path separator or one of the characters :, *, ?, ", <, >, or |. Path components of . and .. are also rejected. This keeps a record value from redirecting output outside of the configured directory.
Generated directories are only created if you also enable mkdir.
Dynamic destinations apply to log records only. Metrics records are always written to fallback_path and fallback_file.
strftime placeholders
Support for strftime placeholders is available in Fluent Bit version 5.1.1 and greater.
Set enable_strftime to true to expand strftime placeholders such as %Y, %m, and %d in path and file. Fluent Bit formats each placeholder using the timestamp of the event being written, expressed in UTC. Because the value comes from the event itself and not from the clock at flush time, records that arrive late are still written to the file for the period in which they occurred.
This parameter is disabled by default. When enable_strftime is false, a percent character in path or file is written literally, which preserves existing filenames that contain one.
When enable_strftime is true, escape every literal percent character in path and file as %%. A % that isn't escaped is consumed as the start of a strftime conversion specifier and is replaced with a time value.
Fluent Bit treats any path or file containing a percent character as a dynamic destination when enable_strftime is true, so fallback_file is required even when the value contains only escaped %% sequences and always resolves to the same destination.
You can combine placeholders with record accessors in the same value. Fluent Bit expands the strftime placeholders first, then resolves the record accessors against the result:
Most rules described in Dynamic destinations apply to placeholders the same way they apply to record accessors. fallback_file is required, resolved destinations are rejected when unsafe, and each distinct destination counts toward max_dynamic_files. Because a new destination is created for every time period you include, choose the smallest unit your retention needs. An hourly layout such as %Y%m%d%H reaches the default max_dynamic_files limit of 1024 after about 42 days of continuous operation.
The static prefix requirement is the exception. Fluent Bit enforces it for record accessors only, so a path can begin with a placeholder. A path of %Y/%m/%d resolves to a relative directory such as 2026/08/17, located inside the Fluent Bit working directory. Begin the value with a static prefix, as in /var/log/fluent-bit/%Y/%m/%d, to keep output under a directory you chose.
Actions for unresolved destinations
Two settings control what happens to a record whose destination Fluent Bit can't use. on_missing_field applies when the record accessor field is missing or resolves to an unsafe value, and on_limit_reached applies when writing to a new destination would exceed max_dynamic_files. Both accept the same actions:
error
Log an error and fail the flush. The chunk isn't retried. Records from the chunk that were already written stay in their files.
drop
Log a warning and discard the record.
fallback
Write the record to fallback_path and fallback_file instead. Requires fallback_file; otherwise Fluent Bit fails to start.
Destination limits
The max_dynamic_files limit counts distinct destinations for this output instance, which bounds the number of files a high-cardinality record field can create. Records that resolve to a destination already counted aren't affected by the limit.
The count is shared by all workers of the output instance, and in v5.2 or later it's enforced consistently when several workers write at the same time. In v5.2 or later, a destination counts as soon as Fluent Bit first tries to write to it, even if opening the file then fails. Destinations aren't removed from the count while Fluent Bit runs. The count starts again only when Fluent Bit restarts or reloads its configuration, and restarting doesn't delete any files. The limit bounds how many destinations one Fluent Bit run can create, not how many files stay on disk. Log rotation only limits the rotated copies of each file and doesn't remove old destinations, so use a separate retention job to delete files that accumulate over time.
When file isn't set, Fluent Bit names each file after the record tag. If path is dynamic, each combination of resolved path and tag-derived filename already counts toward the limit. When path isn't dynamic, tag-derived filenames are limited only if you set max_dynamic_files explicitly, in v5.2 or later. Setting it explicitly to its default value of 1024 still enables this limit. Because every record in a chunk has the same tag, on_limit_reached then applies to the whole chunk.
Dynamic destination example
The following configuration writes each record to a file named after its app field, under a per-namespace directory. Records without both fields go to /var/log/fluent-bit/unrouted.log:
Time-based destination example
The following configuration writes each record to a daily directory derived from the UTC event timestamp. Records whose destination can't be resolved go to /var/log/fluent-bit/unrouted.log:
Get started
You can run the plugin from the command line or through the configuration file.
Command line
From the command line you can let Fluent Bit count up a data with the following options:
Configuration file
In your main configuration file append the following:
Last updated
Was this helpful?