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