Why tty=true(in docker-compose.yml) makes log highlights on Gin app?

Viewed 922

Envs

Docker version 19.03.13, build 4484c46d9d
docker-compose version 1.22.0, build f46880fe

What Happened

I develop very simple RESTful APIs to learn by using Gin.
When I notice that tty=true(in docker-compose.yml) is not required in my code and delete it, the log highlights disappear strangely.

Before deleting tty=true Before deleteing tty=true

After deleting tty=true After deleting tty=true

Codes

docker-compose.yml

version: '3'

volumes:
  vendor:

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 3001:3001
    tty:
      true
    depends_on: 
      - db
  db:
    image: postgres:alpine
    environment:
      POSTGRES_USER: gorm
      POSTGRES_PASSWORD: gorm
      POSTGRES_DB: gorm
      POSTGRES_HOST: db
    ports:
      - 5432:5432

Other codes https://gist.github.com/Asuha-a/521b37c8ac56f5c52a1d4b5a76b2726d

I Want to Know

I have no idea of the reasons. What do you think?

1 Answers

This is solved by comment.

DavidMaze: Code can tell whether stdout is a tty or not, and make decisions about coloration accordingly. In log files you often don't want the color escape codes, which can make the files harder to read.

Me: I'm not sure that I understand your comment especially the subject in the first sentence. Does 'Code' means code of terminal?

DavidMaze: In this case I mean the logging library Gin is using. You can call a function (Google quickly finds me this library) and tell whether stdout is a terminal or a file or a pipe or something else.

Related