Ravindra BagaleCourses & study guides

Chapter 14: Logging and Light Observability

14.2 stdout/stderr and docker logs

Containers usually send application logs to standard output and standard error. Docker captures those streams.

docker ps
docker logs <container_name_or_id>
docker logs --tail 100 -f <container_name_or_id>

What you see: recent lines from the process inside the container. -f follows like tail -f.

Compose:

docker compose logs -f api
docker compose logs --tail 200 api

Tiny example. badge API API prints INFO ready on :8080 then later ERROR db ping failed. You see both with docker logs without SSH-copying random files — if the app writes to stdout.

Habit Why
Log to stdout in containers Platform can ship/collect uniformly
Structured JSON when possible Easier to search fields later
Include level (INFO/WARN/ERROR) Filter noise
Never log secrets Tokens in logs become incidents

Practice task

Write three example log lines for badge API (INFO start, WARN slow query, ERROR 500) with fake request ids — no real secrets.