# How to Monitor a Whole Directory With Fluentd?

Fluentd provides an efficient way to monitor entire directories for log file updates. Let's say you want to track all log files in a directory like `/var/log/app_dir`, which contains multiple logs such as `errors.log`, `success.logs`, and `app.log`.

You can achieve this using the Fluentd `in_tail` plugin. Here's an example configuration:

```text
[label /etc/fluent/fluentd.conf]
<source>
  @type tail
  path /var/log/app_dir/*
  pos_file /var/log/fluentd/tail.pos
  tag your.log.tag
</source>
```

In this configuration, the `tail` input type is used to continuously read log events from files. The `path` parameter is set to `/var/log/app_dir/*`, where the asterisk (`*`) acts as a wildcard to include all files within the specified directory. The `pos_file` parameter is crucial as it helps Fluentd remember the last read position of each file, enabling it to resume from where it left off in case of a restart or interruption.

This setup ensures that Fluentd will monitor and read all log events from every file in the `/var/log/app_dir` directory as they are generated, providing comprehensive log monitoring coverage for the entire directory.


## How to add multiple file paths to fluentd?

If your objective is to monitor certain files within a directory, rather than all files, Fluentd's [`in_tail`](https://docs.fluentd.org/input/tail) plugin allows you to specify multiple paths for targeted log monitoring. For instance, to monitor only `errors.log` and `app.log` in the `/var/log/app_dir` directory, your configuration would look like this:

```text
[label /etc/fluent/fluentd.conf]
<source>
  @type tail
  path /var/log/app_dir/errors.log,/var/log/app_dir/app.log
  pos_file /var/log/fluentd/tail.pos
  tag your.log.tag
</source>
```

In this setup:

- The `tail` input plugin is employed to read log events from the specified files.
- The `path` property is used to list the paths of the individual files you want to monitor. These paths are separated by commas.
- The `pos_file` is an essential element that enables Fluentd to track the last read position of each file. This tracking ensures Fluentd can resume reading from the correct spot after any restarts or disruptions.

When Fluentd runs with this configuration, it will read logs from both `errors.log` and `app.log`, ensuring targeted log collection.

For further insights and advanced configurations in log data management using Fluentd, consider exploring the comprehensive [guide on how to collect, process, and ship 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)