Skip to content

fix(logging): only color console logs on a terminal - #5616

Merged
pimlock merged 1 commit into
mainfrom
fix/plain-console-logs-off-tty/pimlock
Nov 16, 2026
Merged

pimlock merged 1 commit into
mainfrom
fix/plain-console-logs-off-tty/pimlock

Conversation

@pimlock

@pimlock pimlock commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Right now our gateway logs in the GKE look like this:

[2m2026-11-16T19:28:18.631201Z�[0m �[32m INFO�[0m �[1mreconcile�[0m�[1m{�[0m�[3motel.name�[0m�[2m=�[0m"reconcile.sandboxes" �[3mdriver.name�[0m�[2m=�[0mkubernetes �[3mbackend_count�[0m�[2m=�[0m12�[1m}�[0m�[2m:�[0m�[1mdriver�[0m�[1m{�[0m�[3motel.name�[0m�[2m=�[0m"openshell.compute.v1.ComputeDriver/GetSandbox" �[3motel.kind�[0m�[2m=�[0m"client" �[3mdriver.name�[0m�[2m=�[0mkubernetes �[3mrpc.system.name�[0m�[2m=�[0m"grpc" �[3mrpc.method�[0m�[2m=�[0m"openshell.compute.v1.ComputeDriver/GetSandbox" �[3msandbox.id�[0m�[2m=�[0m"4a24a352-bffc-4235-ae11-2d41642c8cbd"�[1m}�[0m�[2m:�[0m�[1mdriver_rpc�[0m�[1m{�[0m�[3motel.name�[0m�[2m=�[0m"openshell.compute.v1.ComputeDriver/GetSandbox" �[3motel.kind�[0m�[2m=�[0m"server" �[3mrpc.system.name�[0m�[2m=�[0m"grpc" �[3mrpc.method�[0m�[2m=�[0m"openshell.compute.v1.ComputeDriver/GetSandbox"�[1m}�[0m�[2m:�[0m �[2mopenshell_driver_kubernetes::driver�[0m�[2m:�[0m Fetching sandbox from Kubernetes �[3msandbox_id�[0m�[2m=�[0m4a24a352-bffc-4235-ae11-2d41642c8cbd �[3mworkspace_mode�[0m�[2m=�[0mshared

This PR fixes that and makes the ANSI color usage consistent across all the spots.
The approach follows what other projects do:

  • if NO_COLOR is set -> output plain text
  • if stdout is a terminal, or FORCE_COLOR is set -> output ANSI color escapes
  • otherwise -> output plain text

Related Issue

No issue required: localized bug fix with the full context in this PR.

Changes

  • New openshell_core::color with stdout_ansi() and stderr_ansi(). NO_COLOR disables color, FORCE_COLOR forces it, and otherwise the stream must be a terminal whose TERM renders ANSI. These are the same rules the CLI already used.
  • The gateway console layer, certgen, the Vault and Kubernetes Secrets credential drivers, and the VM image-preparation worker pass the result to with_ansi.
  • openshell_otel::DriverTracingConfig gains an ansi field, because openshell-otel does not depend on openshell-core. The Docker, Podman, Kubernetes, and VM driver binaries set it.
  • The CLI keeps --color always|never and delegates its auto branch to the shared helper, so the duplicated TERM and env-var rules are removed.
  • Docs: a short "Console Colors" section in docs/observability/accessing-logs.mdx.

Machine-readable JSON console logs (with a GCP-compatible severity field) would be a separate follow-up.

Testing

  • mise run pre-commit passes
  • Unit tests added/updated (the color rules moved into openshell-core with their tests; the CLI resolve tests still pass)
  • E2E tests added/updated (if applicable)

Manual check: ran openshell-gateway with output redirected to a file. All 10 log lines were plain. With FORCE_COLOR=1, all 10 were colored. This has not been checked on GKE.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)

tracing-subscriber's formatter enables ANSI unless NO_COLOR is set and
does no terminal detection, so the gateway, compute drivers, credential
drivers, and certgen wrote escape codes into container logs collected by
GKE and other log pipelines.

Move the CLI's automatic color rules (NO_COLOR, FORCE_COLOR, terminal
plus TERM capability) into openshell_core::color and pass the result to
with_ansi in every long-running binary's console layer. The CLI keeps
--color always|never and delegates its auto branch to the shared helper.

Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the state:accepted A maintainer decided OpenShell should pursue this issue label Nov 16, 2026
@github-actions

Copy link
Copy Markdown

@pimlock
pimlock marked this pull request as ready for review November 16, 2026 20:07
@pimlock
pimlock requested a review from TaylorMutch November 16, 2026 20:07
@pimlock
pimlock enabled auto-merge November 16, 2026 20:19
@pimlock
pimlock added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit f0799e2 Nov 16, 2026
96 checks passed
@pimlock
pimlock deleted the fix/plain-console-logs-off-tty/pimlock branch November 16, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:accepted A maintainer decided OpenShell should pursue this issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants