Skip to main content
In this lesson you’ll add a file-based scrape target to Alloy so application logs are forwarded to Grafana Loki. We’ll:
  1. Confirm you can query existing system logs with LogQL.
  2. Verify the application is writing logs to a local file.
  3. Update Alloy’s configuration to scrape that file and send logs to Loki.
  4. Restart Alloy and verify logs appear in Grafana.

1) Verify system logs (LogQL)

Start by confirming you can query system logs using a LogQL query:
This validates that Loki is receiving and indexing files from the configured system log paths.

2) Confirm the application is writing to a file

On the node, inspect the application directory and confirm the app log exists:
Tail the application log to ensure entries are being written in real time:

3) Update Alloy configuration to scrape the application log

Edit /etc/alloy/config.alloy and add a file match for the application log plus a Loki write endpoint. Below is a concise example showing the minimal blocks required to collect both system logs (wildcard path) and the specific application log:
Key points:
  • path_targets identifies files to scrape; for the app example we used /home/bob/app/app.log.
  • tail_from_end = true ensures the collector tails from the end of the file on startup, avoiding re-ingestion of historical lines after restarts.
  • You can either reuse an existing source and add targets, or create a dedicated loki.source.file for application logs as shown.
Table of configuration blocks
Be sure to use sudo when editing /etc/alloy/config.alloy and restarting the service.

4) Restart Alloy and confirm it’s running

After saving your changes, restart Alloy and check service status:
Example status output:

5) Verify logs in Grafana / Loki

Open Grafana (or your Loki query UI) and run a LogQL query targeting the application filename:
To filter for specific text (for example, Node.js-specific entries):
After the configuration update and restart, you should see your application JSON logs streaming into Loki and visible in Grafana Explore.

Watch Video