Read the ANSI colors in a captured log, instead of the codes

You save the output of docker compose logs or a CI run to a file, open it, and half of every line is ESC[32m, ESC[0m, [36mweb_1 |. The log is fine. Those are ANSI escape codes - the instructions that told your terminal which colors to use. A terminal interprets them; a text editor shows you the raw bytes, and on a compose log with per-service colors they can take up more of the width than the messages.

Quick reads in the Terminal

less -R passes color escapes through raw, so the colors render:

less -R compose.log

cat compose.log renders too - your terminal is doing the interpreting - but it scrolls straight past and leaves you with the buffer.

Stripping the codes

If you need clean text - to diff it, grep it, or paste it somewhere - the usual answer is sed:

sed 's/\x1b\[[0-9;]*m//g' compose.log > clean.log

This removes the common color codes. It is also lossy and slightly fragile: you now have a second file, and escape sequences beyond simple colors can slip through. Fine as a one-off; annoying as a habit.

A viewer that reads them the way a terminal does

Log Viewer treats escape codes as what they are: formatting. It paints the colors the log asked for and takes the codes out of the text - on a compose log that is most of the window's width back at a stroke. Prefer plain? Settings can drop them entirely, or leave them visible if what you are debugging is the codes themselves. Your own highlight rules - errors red, warnings amber - win over what the log asked for, and copying a line gives you the text you could see, not the escape bytes you couldn't.

A log captured from a terminal: the colors painted, the codes gone.
A log captured from a terminal: the colors painted, the codes gone.

Free on the Mac App Store, works entirely offline.

FAQ

Why does my saved log show ESC[0;32m instead of colors?

Programs emit ANSI escape codes to color terminal output. When output is redirected to a file, the codes are saved as bytes; anything that isn't a terminal shows them as text.

How do I strip ANSI codes from a log file?

sed 's/\x1b\[[0-9;]*m//g' handles the common color codes. A viewer that interprets them instead keeps the color and the clean text at once.

Does copying from Log Viewer include the escape codes?

No - copying gives you what you could see, with the codes already removed.