Florian Ludewig
Florian Ludewig

Reputation: 6002

Docker Compose Up - Remove Service Name in Log Output

Is it possible to remove the service name in the log output of docker-compose up?

My logs are currently looking like this:

serviceA        | log1
serviceB        | log2
serviceB        | log3
serviceA        | log4

But I want them to look like this:

log1
log2
log3
log4

The documentation states, that you can configure the logging for services like this:

version: "3.7"
services:
  some-service:
    image: some-service
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

But I couldn't find any option to remove the service name from the logs when running docker-compose up.

Update

As proposed by EchoMike444, I've tried the following command:

docker-compose up --no-color 2>&1 | sed 's/^[^ ]*  | //'

with the following docker compose file:

version: "3"
services:
  consumer:
    image: debian:stretch-slim
    command:
      [
        "bash",
        "-c",
        "while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done ",
      ]
  ideas:
    image: debian:stretch-slim
    restart: always
    command:
      [
        "bash",
        "-c",
        "while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done ",
      ]

The output looks like this

ideas_1     | Sun Oct 20 05:56:23 UTC 2019 99295bdcbf2c
ideas_1     | Sun Oct 20 05:56:25 UTC 2019 99295bdcbf2c
Sun Oct 20 05:56:25 UTC 2019 dd45c5900159
ideas_1     | Sun Oct 20 05:56:27 UTC 2019 99295bdcbf2c
ideas_1     | Sun Oct 20 05:56:27 UTC 2019 99295bdcbf2c
Sun Oct 20 05:56:27 UTC 2019 dd45c5900159
Sun Oct 20 05:56:29 UTC 2019 dd45c5900159
ideas_1     | Sun Oct 20 05:56:30 UTC 2019 99295bdcbf2c

So it is working for service consumer, but not for ideas.

Upvotes: 3

Views: 1067

Answers (2)

Alex Vko
Alex Vko

Reputation: 41

It seems you can now, this PR was merged:

https://github.com/docker/compose/pull/7435

ex: docker-compose up --no-log-prefix

Upvotes: 4

EchoMike444
EchoMike444

Reputation: 1692

Currently you can not remove the prefix , I did not see a option in the source code .

docker-compose is wrote in python feel free to patch .

https://github.com/docker/compose/blob/master/compose/cli/log_printer.py

A workaround will :

 docker-compose up --no-color 2>&1 | sed 's/^[^ ]*  *| //' 

or

 docker-compose up -d
 docker-compose logs --no-color -f 2>&1 | sed 's/^[^ ]*  *| //'

I tested MacOS and Linux with this very small docker-compose.yaml

version: '3.7'
services:
  serviceA:
    image: debian:stretch-slim
    command: ["bash","-c","while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done "]
  serviceB:
    image: debian:stretch-slim
    restart: always
    command: ["bash","-c","while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done "]

Upvotes: 1

Related Questions