Docker Community Forums

Share and learn in the Docker community.

How to turn off the log color mark output by stdout?

I used filebeat to collect the logs output by container stdout, but why are the logs marked with colors? This makes the log structure very messy, is there any way to turn off the color mark?

Can you elaborate more on why you think that docker would be responsible for that behavior?

Docker logs show whatever is printed to /dev/stdout and /dev/stderr. Docker is neither adding, nor removing color codes of your logs. It’s the resposiblity of the application inside the container that generates the logs.

@meyay is right. Docker will not add colors to your logs, but it can prevent it to happen if your application sends those color codes based on whether you have a terminal or not. Try this:

docker run --name with-colors -t bash ls
docker logs with-colors
# Now you have colors in the log

docker run --name without-colors bash ls
docker logs without-colors
# Now you don't have colors in the log

If for example Elastic APM see you have terminal in the container it can produce color output. The other option is using a parameter to control colors as ls does

docker run --name ls-without-colors -t bash ls --color=never
docker logs ls-without-colors

How does your logging work? What is on the shared picture? Is this Kibana? Since the color characters are before Elastic.APM[0] I would say APM is responsible for it but I don’t know Elastic APM yet.

Thank you for your reply.
Sorry, I haven’t found the reason at first. According to your reply, I probably understand what you mean. It is indeed not controlled by docker, but if I change output to file, then there will be no color marking, only stdout is used. Will appear. I guess it’s a problem with the log framework.

Thank you for sharing a good learning example. I also guess that it is the problem of the service itself (that is, elastic APM). The picture is the log seen on kibana.
But this elastic APM does not provide log color configuration.

There is pretty: false but this should be the default. I could not find other relevant configuration either. And make sure you don’t configure terminal (tty) for the containers.

Thank you for taking the time to help me troubleshoot. I posted a discussion on the elastic forum, and no one has responded until now.
What does “And make sure you don’t configure terminal (tty) for the containers.” mean? Terminal refers to dockerfile base output? Or docker command console?

See my previous example docker run codes with and without -t. The long version of this parameter is --tty which mstands for Teletype which related to terminals so I usually refer -t as terminal. Sorry if I misled you. You TTY can be configured in command line, in a Docker Compose file or in a Kubernetes manifest file. So basically anywhere. Search for docker TTY for more details.

Thank you for your explanation, I have confirmed that this color mark comes from the underlying framework of dotnet core.