user9972552
user9972552

Reputation:

How to see the live debug logs of docker container

This is the command to check the docker container logs(info level by default) live:

 docker logs -f CONTAINER_ID

But what if I want to check the live debug logs which I have logged in my code at debug level?

Upvotes: 6

Views: 20815

Answers (2)

Adiii
Adiii

Reputation: 60066

You can run the container in foreground mode so you will able to see log.

docker run -it --rm my_node_app

-it keep the container running in foreground as a result you will able to see your container logs.

You will able to see live logs same like running application in terminal.

But what if I want to check the live debug logs which I have logged in my code at debug level?

The container output logs totally depend upon the stdout/stderr of the main process that is defined in CMD.

You can filter Debug logs from the log output, as docker does not know the logs format it just print the logs which is available in the form of stdout/stderr.

You can try

docker logs -f container_id | grep "Debug"

If the logs formate contains debug or similar pattern.

Upvotes: -1

davidxxx
davidxxx

Reputation: 131466

This is the command to check the docker container logs(info level by default) live:

docker logs -f CONTAINER_ID

Not really, docker logs CONTAINER_ID doesn't cope with verbosity level. It simply output the container STDOUT and STDERR.

But what if I want to check the live debug logs which I have logged in my code at debug level?

That is a very good question.
You could statically (via configuration file) configure your logger appender to write to stdout for all logs (debug and above).
But as side effect, it will log always with that level. For a simple test, it is fine but for a long time running container it may be annoying.
In that case, a dynamic approach to set the logger level is be better (a basic rest controller may very well do the job).
And in that way docker logs -F CONTAINER_ID will output more or less logs according to the current level.

Upvotes: 6

Related Questions