Skip to content

Support custom pretty placeholders - #386

Merged
terehov merged 2 commits into
developmentfrom
feat/custom-pretty-placeholders
Oct 18, 2026
Merged

terehov merged 2 commits into
developmentfrom
feat/custom-pretty-placeholders

Conversation

@terehov

@terehov terehov commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Supersedes #380 by @clayzx (cherry-picked with their authorship; thank you!) with a follow-up commit addressing the review.

Feature

pretty.placeholders registers custom {{token}}s for pretty.template. Each callback gets (meta, pretty) and returns a string or number; style the token through pretty.styles like a built-in, so a composite value such as HH:mm:ss.SSS is colored as one unit. Only referenced tokens run, a throw renders empty (never drops the log), built-in names are reserved, sub-loggers inherit the parent's map. Meta template only — error templates and JSON output are unchanged.

new Logger({
  pretty: {
    template: "{{shortTime}} {{logLevelName}} ",
    placeholders: { shortTime: (meta) => meta.date.toISOString().slice(11, 23) },
    styles: { shortTime: "blackBright" },
  },
});

Follow-up on top of #380

  • Callbacks may return numbers as well as strings.
  • IPrettyLogStyles accepts any key so custom tokens can be styled; a misspelled built-in key is therefore reported at runtime instead (UNKNOWN_PRETTY_STYLE with a did-you-mean; dev warning, throws under strictConfig).
  • KNOWN_PRETTY_PLACEHOLDERS moved to src/internal/prettyPlaceholders.ts so internal/ no longer imports core/settings.
  • Docs: README ### Custom placeholders subsection + settings table, RECIPES 16, llms.txt pretty bullet, CHANGELOG 5.3.0 entry.
  • Browser bundle budget 22,400 → 23,000 bytes (measured 22.24KB gzip; the feature plus its validation).

Verification

Vitest 1693 tests at 100% coverage, Biome, check-doc-sync, audit-sideeffects, build, Deno adapter, Bun, and all 321 Playwright tests on Chromium/Firefox/WebKit.

clayzx and others added 2 commits October 18, 2026 22:21
Callbacks may return numbers as well as strings. IPrettyLogStyles now
accepts any key so custom tokens can be styled, so a misspelled built-in
key is reported at runtime instead (UNKNOWN_PRETTY_STYLE, with a
did-you-mean; throws under strictConfig). KNOWN_PRETTY_PLACEHOLDERS moves
to internal/ so metaFormatting no longer imports core/settings. Docs land
in the README pretty section, RECIPES 16 and the llms.txt pretty bullet;
the browser bundle budget grows to 23_000 for the feature.
@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a3699f9) to head (924f02e).
⚠️ Report is 9 commits behind head on development.

Additional details and impacted files
@@              Coverage Diff              @@
##           development      #386   +/-   ##
=============================================
  Coverage       100.00%   100.00%           
=============================================
  Files               53        54    +1     
  Lines             4632      4660   +28     
  Branches          1417      1433   +16     
=============================================
+ Hits              4632      4660   +28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@terehov
terehov merged commit 9455437 into development Oct 18, 2026
11 checks passed
@terehov
terehov deleted the feat/custom-pretty-placeholders branch October 18, 2026 19:23
@terehov terehov mentioned this pull request Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants