🔠Want to centralize and monitor your logs?
Go to Logtail and start your log management in 5 minutes.
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:
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:
<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:
<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.
Go to Logtail and start your log management in 5 minutes.
Fluentd offers the capability to set up log rotation, particularly useful when managing large volumes of logs that consume significant disk space. This feature can be configured through Fluentd's s...
Conditional statements can be seamlessly integrated into Fluentd's record_transformer plugin. Here’s how you can do it: <filter mylogs> @type recordtransformer enableruby true <record> is...
Here is how you can add tags to Fluentd events. Let's assume you configured Fluentd to process Nginx access logs from the access.log file with a source configuration like this: <source> @type ta...
Learn how to use Fluentd to collect, process, and ship log data at scale, and improve your observability and troubleshooting capabilities.
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usWrite a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github