I'm trying to get logs into Grafana Loki via Promtail. Both services are running in their own Docker container. Because Promtail collects logs from a filepath, my actual application is writing logs to a file on the host.
This file gets mounted into Promtail and the scraper will incrementally push these logs to Loki. The problem I'm running into is that the logs only reflect in the container once my application dies. I assume this is because the file is closed. If I tail the file from the container, I don't see realtime updates at all. I've tried a standard volume and a bind mount.
Here is a sample snippet of my docker-compose file:
promtail:
image: grafana/promtail:2.8.0
volumes:
- ./promtail:/etc/promtail
- /var/log:/var/log
- type: bind
source: ./logs/api.log
target: /etc/promtail/api.log
command: -config.file=/etc/promtail/config.yml
networks:
- loki
My log file is written from a Go application using Uber Zap. On the host machine, I can see the logs being written to the file just fine. What am I misunderstanding here? I want strong consistency between the file on the host and the contents of that file within the counter its mounted in so I can push the logs in realtime.