charmbracelet / log

A minimal, colorful Go logging library 🪵
MIT License
2.4k stars 67 forks source link

No color outputs in docker compose #138

Closed mpiorowski closed 3 months ago

mpiorowski commented 4 months ago

Describe the bug No color outputs in when running go app in docker compose

image

mpiorowski commented 4 months ago

That's my current setup:

func InitLogger() {
    var level log.Level
    if LOG_LEVEL == "info" {
        level = log.InfoLevel
    } else {
        level = log.DebugLevel
    }

    logger := log.NewWithOptions(os.Stderr, log.Options{
        ReportCaller:    true,
        ReportTimestamp: true,
        TimeFormat:      time.Kitchen,
        Level:           level,
    })
    slog.SetDefault(slog.New(logger))
}
aymanbagabas commented 4 months ago

How are you running your image? You need to use docker run -it <image> for an interactive TTY container.

mpiorowski commented 3 months ago

@aymanbagabas I run the docker compose with -it: image

Still not working: image

aymanbagabas commented 3 months ago

What's your $TERM inside the docker? Usually it defaults to TERM=xterm which indicates no colors. Try docker run -e TERM=xterm-256color -e COLORTERM=truecolor -it <image>

mpiorowski commented 3 months ago

Yep, tty: true + this setup helped :)

image

thanks!