How to Add Tags to Fluentd Events

Better Stack Team
Updated on February 5, 2024

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:

/etc/fluent/fluentd.conf
<source>
   @type tail
   path /var/log/nginx/access.log
   pos_file /var/log/access.log.pos
   format nginx
</source>

To organize and identify these logs effectively, you can assign a specific tag using the tag property in the configuration. Here's how you can set it:

/etc/fluent/fluentd.conf
<source>
   @type tail
   path /var/log/nginx/access.log
   pos_file /var/log/access.log.pos
   tag nginx.access
   format nginx
</source>

In this example, the logs are tagged with nginx.access. This tag is crucial as it allows you to filter or match logs based on it in subsequent Fluentd configurations.

Now, with the tag defined, it can be referenced in a match or filter directive. Here's an example of using the match directive to forward all logs with the nginx.access tag to standard output:

 
<source>
   @type tail
   path /var/log/nginx/access.log
   pos_file /var/log/access.log.pos
   tag nginx.access
   format nginx
</source>

<match nginx.access>
   @type stdout
</match>

This setup ensures that all log events tagged as nginx.access are directed to the standard output, providing a streamlined way to manage and view these specific logs.

🔭 Want to centralize and monitor your logs?

Go to Logtail and start your log management in 5 minutes. [/summary]

Better Uptime Dashboard

Make your mark

Join the writer's program

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 us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write 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.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github