Skip to main content

should_colorize

Function should_colorize 

Source
pub fn should_colorize() -> bool
Expand description

Determine whether console log output should include ANSI color codes.

Priority order (highest to lowest):

  1. NO_COLOR env var set → no color (https://no-color.org/ convention)
  2. FORCE_COLOR env var set → force color (useful in Docker/CI)
  3. stderr is a TTY → color (interactive terminal)
  4. stderr is not a TTY → no color (piped/redirected)

§CUSTOMIZE: Docker containers

Docker containers often do NOT have a TTY attached to stderr, which would disable color by rule 4. But docker compose logs renders ANSI codes correctly, so operators benefit from colors.

Set FORCE_COLOR=1 in your docker-compose.yml or Dockerfile:

environment:
  FORCE_COLOR: "1"

§CUSTOMIZE: CI/CD pipelines

Most CI systems (GitHub Actions, GitLab CI) support ANSI codes. Set FORCE_COLOR=1 in your CI environment variables to enable color logs.