charmbracelet / log

A minimal, colorful Go logging library 🪵
MIT License
2.18k stars 61 forks source link

colors doesn't work on github actions out of the box #130

Open os14 opened 1 month ago

os14 commented 1 month ago

Is your feature request related to a problem? Please describe. we have a cli tool that uses charmbracelet/log for logging, locally it prints nice colors, but in github actions terminal it doesn't print colors.

Describe the solution you'd like perhaps the issue is on github side but i would like to get a workaround for this or ideally make it works out of the box.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context local: image

github actions: image

aymanbagabas commented 1 month ago

@os14 this is intentional, GitHub Actions and other CIs export CI=1 to indicate that the application is running in a CI environment. Some CIs don't support colors. Termenv, the underlying library currently used to render colors, detects the CI environment variable and disables colors accordingly. To enable colors make sure that you set CI='' in your workflow or application.

paleboot commented 2 weeks ago

@os14 this is intentional, GitHub Actions and other CIs export CI=1 to indicate that the application is running in a CI environment. Some CIs don't support colors. Termenv, the underlying library currently used to render colors, detects the CI environment variable and disables colors accordingly. To enable colors make sure that you set CI='' in your workflow or application.

I found that, in GitHub Actions at least, all it takes is CLICOLOR_FORCE=1.

I tested the logics here:

Using the following snippet:

// fatih/color
white := color.New(color.FgBlue)
boldWhite := white.Add(color.Bold)
boldWhite.Println("Colors using fatih/color")

// charmbracelet/log
logger := log.New(os.Stdout)
logger.Info("Colors using charmbracelet/log")

if isatty.IsTerminal(os.Stdout.Fd()) {
    fmt.Println("IsTerminal: true")
} else {
    fmt.Println("IsTerminal: false")
}
fmt.Printf("TERM: %s\n", os.Getenv("TERM"))
fmt.Printf("CI: %s\n", os.Getenv("CI"))
fmt.Printf("CLICOLOR_FORCE: %s\n", os.Getenv("CLICOLOR_FORCE"))

and adding the following to the Github Actions step, more info on that here:

shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"'

Here are the results: