Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove prefix with service name from logs?

docker-compose inserts prefixes like service_1 | in the beginning of every line of output. I use this container for testing and this kind of improvement (very useful in other cases) mess my debugging logs and I want to remove it for this service. Documentation have no information about this question. Any ideas?
my docker-compose.yml:

version: '3'
services:
  rds:
    image: postgres:9.4
    ports:
      - ${POSTGRES_PORT}:5432
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
  dynamo:
    image: iarruss/dynamo-local-admin:latest
    ports:
      - ${DYNAMODB_PORT}:8000
  python:
    container_name: python
    image: iarruss/docker-python2:latest
    depends_on:
      - rds
      - dynamo
    environment:
      POSTGRES_HOST: rds
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      DYNAMODB_HOST: dynamo

Edit: Clarify expected result

Current output:

python             |
python             | collected 511 items
python             |
python             | tests/test_access.py
python             |

Expected output:

collected 511 items

test_access.py                                                     
like image 554
El Ruso Avatar asked May 15 '18 23:05

El Ruso


1 Answers

docker compose logs has a --no-log-prefix flag that removes the prefix.

For example

# start all services in background
docker compose up -d

# show logs for all services, without prefix (-f means follow the logs)
docker compose logs -f --no-log-prefix

# or, for a single service called foo
docker compose up foo -d
docker compose logs foo -f --no-log-prefix

See the documentation here

like image 116
davnicwil Avatar answered Sep 21 '22 23:09

davnicwil