# How to Use Environmental Variables in Fluentd Config

Fluentd, starting from version v1.13.0, allows the integration of environment variables within its configuration using the syntax `#{ENV['YOUR_ENV_VARIABLE']}`.

For instance, if you've defined an environment variable `SECRET_KEY` in your system, it can be used in the Fluentd configuration file as follows:

```text
some_field "#{ENV['SECRET_KEY']}"
```

Remember to enclose the syntax in double quotes, not single quotes.

This setup dynamically assigns the value of the `SECRET_KEY` environment variable to `some_field`.

To illustrate with a more specific example, consider a `match` block in Fluentd's configuration used for forwarding logs to Better Stack, which requires a source token like `W8QhqAQ82MVn1nqgPZoe2T9G`. The environment variable can be utilized in this context as shown:

```text
<label /etc/fluent/fluentd.conf>
  <match docker.nginx.**>
    @type logtail
    @id output_nginx_logtail
    source_token "#{ENV['SOURCE_TOKEN']}"
    flush_interval 2 # in seconds
  </match>
</label>
```

Additionally, environment variables can be employed for setting tags. For example, using the `FLUENTD_TAG` environment variable to specify a tag would look like this:

```text
<match "docker.#{ENV['FLUENTD_TAG']}">
  ...
</match>
```

For a comprehensive understanding of Fluentd and its capabilities in log data management, you can refer to [this guide on collecting, processing, and shipping log data with Fluentd](https://betterstack.com/community/guides/logging/fluentd-explained/).

[summary]
## 🔭 Want to centralize and monitor your logs?
Go to [Logtail](https://betterstack.com/logtail/) and start your log management in 5 minutes.
[/summary]
![Better Uptime Dashboard](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/08b5b6cb-f57b-4ff4-cf1d-b303b8a94e00/public =1247x768)