✦ For everyone, free.

Practical knowledge for real and everyday life

Home

9.4.3.3 Logs Tail Filtering

A focused guide to Logs Tail Filtering, connecting core concepts with practical Docker and container operations.

Logs tail filtering, through the --tail flag on docker compose logs, limits output to a specific number of the most recent log lines, avoiding an overwhelming dump of a service's entire log history when only its recent behavior is actually relevant.

Limiting Output to a Specific Number of Recent Lines

The --tail flag, given a number, restricts output to that many of the most recent lines.

docker compose logs --tail=100 api

This displays only the most recent 100 lines from api's log history, rather than its entire accumulated output.

Why This Matters for a Long-Running Service

A service that's been running and logging for an extended period can accumulate a very large volume of log output — without tail filtering, simply requesting its logs could produce an unmanageably large amount of text.

docker compose logs api
docker compose logs --tail=50 api

The second command produces a far more manageable, immediately useful amount of output, focused on recent activity rather than the service's entire history.

Combining Tail Filtering With Follow Mode

These two options work well together, showing recent history before switching to live streaming of new output.

docker compose logs --tail=20 -f api

This displays the most recent 20 lines for immediate context, then continues following new log output as it's produced.

Choosing an Appropriate Tail Count for the Situation

The right number of lines depends on the situation — a quick check might need only a handful of recent lines, while investigating an issue might call for a larger amount of recent history to capture relevant context.

docker compose logs --tail=500 api | grep ERROR
Why Logs Tail Filtering Matters

This filtering option makes log inspection practical and efficient, avoiding the noise and overwhelm of a service's complete log history when only its recent, immediately relevant behavior actually needs reviewing.