Video in progress

How do you follow the logs of a running application in real time?

It depends on where it runs: tail -f for a plain file, journalctl -u name -f for a systemd service, docker logs -f in Docker, kubectl logs -f in Kubernetes.

📖 Answer

# if it writes to a file
tail -f /var/log/shop-api/app.log
tail -n 200 -f app.log | grep ERROR

# systemd service
journalctl -u shop-api -f --since "10 min ago"

# docker
docker logs -f --tail 100 shop-api

# kubernetes
kubectl logs -f deploy/shop-api
kubectl logs shop-api-7d9f-abcde --previous   # log of the previous, crashed container

Remember --previous: if a Pod restarts over and over, the current container has not written anything yet, and the cause is in the log of the previous one.

The rule in the container world: the app writes logs to stdout, not to a file. Then the platform collects them itself and ships them to a central system such as Loki or ELK. A log written to a file disappears together with the container.