Skip to content

fix(evlog): use CSS formatting for browser DevTools instead of ANSI escape codes#164

Merged
HugoRCD merged 4 commits intoHugoRCD:mainfrom
oritwoen:fix/browser-pretty-print
Mar 13, 2026
Merged

fix(evlog): use CSS formatting for browser DevTools instead of ANSI escape codes#164
HugoRCD merged 4 commits intoHugoRCD:mainfrom
oritwoen:fix/browser-pretty-print

Conversation

@oritwoen
Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #160

📚 Description

prettyPrintWideEvent() and emitTaggedLog() use ANSI escape codes (\x1B[...]) unconditionally when pretty mode is enabled. Chrome DevTools has partial ANSI support, so colored output works there. Firefox DevTools does not support ANSI at all, rendering raw sequences like [2m, [36m, [0m inline with the log text.

The client-side logger (src/runtime/client/log.ts) already handles this correctly by using %c CSS formatting for browsers. This PR brings the same approach to the standalone logger.ts pretty printer.

What changed in logger.ts:

  • Added a cssColors constant mapping ANSI color names to their CSS %c equivalents
  • Added getCssLevelColor() for level-based CSS colors (mirrors the existing getLevelColor())
  • Added prettyPrintWideEventBrowser() that formats wide events with %c CSS directives instead of ANSI codes
  • prettyPrintWideEvent() now checks isClient() and delegates to the browser variant
  • emitTaggedLog() now checks isClient() and uses CSS formatting for tagged logs

The isClient() utility already existed in utils.ts but wasn't used in logger.ts.

Tests: Added test/logger-browser.test.ts with 5 test cases covering tagged logs, wide events, tree branches, status colors, and duration formatting. Uses vi.mock to override isClient() and verifies that output contains %c directives with no ANSI escape sequences.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 10, 2026

@oritwoen is attempting to deploy a commit to the HRCD Projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

Thank you for following the naming conventions! 🙏

@github-actions github-actions bot added the bug Something isn't working label Mar 10, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d359382fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const levelColor = getCssLevelColor(level)
const timestamp = new Date().toISOString().slice(11, 23)
console.log(
`%c${timestamp}%c %c[${tag}]%c ${message}`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape dynamic fields in browser console format strings

Interpolating tag/message directly into a %c format string means any user or app text containing browser console tokens like %s, %d, or %c is treated as formatting directives instead of literal text, which can consume style args and corrupt the rendered log line. This is a regression from the ANSI path (which treated % literally), so logs become inaccurate for inputs like percent-heavy messages or paths; dynamic segments should be escaped (e.g. %%%) or passed as separate console arguments.

Useful? React with 👍 / 👎.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 13, 2026

npm i https://pkg.pr.new/evlog@164
npm i https://pkg.pr.new/@evlog/nuxthub@164

commit: 5b6d874

@HugoRCD HugoRCD merged commit d84b032 into HugoRCD:main Mar 13, 2026
9 of 10 checks passed
@oritwoen oritwoen deleted the fix/browser-pretty-print branch March 13, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Incorrect rendering of logs in Firefox

2 participants