--- last_modified_on: "2020-07-13" delivery_guarantee: "at_least_once" component_title: "File" description: "The Vector `file` sink streams `log` events to a file." event_types: ["log"] function_category: "transmit" issues_url: https://github.com/timberio/vector/issues?q=is%3Aopen+is%3Aissue+label%3A%22sink%3A+file%22 operating_systems: ["Linux","MacOS","Windows"] sidebar_label: "file|[\"log\"]" source_url: https://github.com/timberio/vector/tree/master/src/sinks/file status: "prod-ready" title: "File Sink" unsupported_operating_systems: [] --- import Fields from '@site/src/components/Fields'; import Field from '@site/src/components/Field'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; The Vector `file` sink [streams](#streaming) [`log`][docs.data-model.log] events to a file. ## Configuration ```toml title="vector.toml" [sinks.my_sink_id] # General type = "file" # required inputs = ["my-source-or-transform-id"] # required healthcheck = true # optional, default path = "vector-%Y-%m-%d.log" # required # Encoding encoding.codec = "ndjson" # required ``` ```toml title="vector.toml" [sinks.my_sink_id] # General type = "file" # required inputs = ["my-source-or-transform-id"] # required healthcheck = true # optional, default idle_timeout_secs = "30" # optional, default path = "vector-%Y-%m-%d.log" # required # Encoding encoding.codec = "ndjson" # required encoding.except_fields = ["timestamp", "message", "host"] # optional, no default encoding.only_fields = ["timestamp", "message", "host"] # optional, no default encoding.timestamp_format = "rfc3339" # optional, default ``` ### encoding Configures the encoding specific sink behavior. #### codec The encoding codec used to serialize the events before outputting. #### except_fields Prevent the sink from encoding the specified labels. #### only_fields Limit the sink to only encoding the specified labels. #### timestamp_format How to format event timestamps. ### healthcheck Enables/disables the sink healthcheck upon start. ### idle_timeout_secs The amount of time a file can be idle and stay open. After not receiving any events for this timeout, the file will be flushed and closed. ### path File name to write events to. See [Template Syntax](#template-syntax) for more info. ## How It Works ### Dynamic File And Directory Creation Vector will attempt to create the entire directory structure and the file when emitting events to the file sink. This requires that the Vector agent have the correct permissions to create and write to files in the specified directories. ### Environment Variables Environment variables are supported through all of Vector's configuration. Simply add `${MY_ENV_VAR}` in your Vector configuration file and the variable will be replaced before being evaluated. You can learn more in the [Environment Variables][docs.configuration#environment-variables] section. ### Streaming The `file` sink streams data on a real-time event-by-event basis. It does not batch data. ### Template Syntax The [`path`](#path) options support [Vector's template syntax][docs.reference.templating], enabling dynamic values derived from the event's data. This syntax accepts [strptime specifiers][urls.strptime_specifiers] as well as the `{{ field_name }}` syntax for accessing event fields. For example: ```toml title="vector.toml" [sinks.my_file_sink_id] # ... path = "vector-%Y-%m-%d.log" path = "application-{{ application_id }}-%Y-%m-%d.log" # ... ``` You can learn more about the complete syntax in the [templating reference][docs.reference.templating]. [docs.configuration#environment-variables]: /docs/setup/configuration/#environment-variables [docs.data-model.log]: /docs/about/data-model/log/ [docs.reference.templating]: /docs/reference/templating/ [urls.strptime_specifiers]: https://docs.rs/chrono/0.4.11/chrono/format/strftime/index.html#specifiers