Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to colorize logs for docker container

I have container which in logs sometimes write key word which is for me important, and I want to highlight this word in color in my terminal, but also important is still see all content logs in real time (--follow). I just tried command

docker logs -f my_app --tail=100 | grep --color -E '^myWord'

but not working.

So exist some way to do this ?

like image 677
Mbded Avatar asked Sep 02 '17 14:09

Mbded


People also ask

What is the docker command for container logs?

First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.

How can we see the logs from a running container?

The docker logs command shows information logged by a running container. The docker service logs command shows information logged by all containers participating in a service. The information that is logged and the format of the log depends almost entirely on the container's endpoint command.

What is TTY mode docker?

The -t (or --tty) flag tells Docker to allocate a virtual terminal session within the container. This is commonly used with the -i (or --interactive) option, which keeps STDIN open even if running in detached mode (more about that later).


1 Answers

I use ccze. as @aimless said, grc is the great utility also. It easy to install by sudo apt install ccze for debian/ubuntu-like OS

But if you want to colorize stderr, you need to redirect stderr output to stdout. For example:

docker logs -f my-app 2>&1 | ccze -m ansi

arg -m ansi helps if you want to scroll output normally

like image 58
spiilmusic Avatar answered Oct 31 '22 03:10

spiilmusic