fix(core): ObjectLogger honors NO_COLOR and TTY detection before emitting ANSI colors#3111
Merged
Merged
Conversation
…ting ANSI colors The kernel/plugin logger colorized pretty-format level tags unconditionally, so NO_COLOR=1 runs and piped/CI output still carried ANSI escapes, breaking plain-text log scanners (publish-smoke.sh had to strip ANSI before grepping). Per no-color.org, color is now emitted only when the destination stream (stdout, or stderr for error/fatal) is an interactive TTY and NO_COLOR is unset or empty. Interactive terminals keep colorized output. The optional file destination always receives plain text now. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 22 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
This was referenced Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
os serve/os dev接线的内核插件日志(ctx.logger=ObjectLogger,默认pretty格式)无条件给 level 标签着色,NO_COLOR=1也不例外:违反 no-color.org 约定,且 CI 里纯文本 grep 会漏掉 ERROR 行 —— scripts/publish-smoke.sh(#3100)就是因此被迫先 strip ANSI 再扫日志(该兜底保留不动)。
修复(只动
packages/core/src/logger.ts,不动调用点/spec)按 no-color.org 约定,
pretty格式仅在满足以下两个条件时才输出 ANSI 色码:NO_COLOR未设置或为空 —— 任何非空值(含0)都禁用颜色。交互式终端默认行为不变(仍着色);管道/重定向/CI 输出恒为纯文本;可选的
file目的地现在恒写纯文本(此前会把色码写进日志文件)。json/text格式不受影响。浏览器 bundle(@objectstack/client复用此模块)无process/TTY → 纯文本,保持 browser-safe。验证
logger.test.ts新增 "Color emission (no-color.org)" 7 例(TTY 默认着色 / 非空 NO_COLOR 禁用含'0'/ 空串视为未设 / 非 TTY 无色 / stderr 门控 error 色 / 文件目的地无 ANSI)。@objectstack/core356 测试全绿。ERROR头与原报告字节一致)。pnpm dev -- --fresh+NO_COLOR=1冒烟,启动日志零 ESC。相关
logger.file静默失效,__require('fs')抛错被catch {}吞掉)—— 本 PR 不处理。@objectstack/corepatch。🤖 Generated with Claude Code