Skip to content

Support LogTape formatter selection - #867

Merged
dahlia merged 6 commits into
mainfrom
packages/logtape/formatters
Jul 3, 2026
Merged

Support LogTape formatter selection#867
dahlia merged 6 commits into
mainfrom
packages/logtape/formatters

Conversation

@dahlia

@dahlia dahlia commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Why this shape

@optique/logtape already had enough structure to choose a log level and an output destination, but the output format still had to be wired by hand. That left a gap between the parser result and the sink that actually writes records: the CLI could choose where logs go, but not how records are rendered there.

This PR keeps that choice in the same data flow. textFormatter() is a value parser for LogTape's built-in text formatter names, and LogOutput can now carry the selected formatter to createSink(). That means a CLI can parse:

logOutput({ formatter: "--log-format" })

and the selected formatter is applied later when the console or file sink is created.

The preset follows the same model, but keeps formatter at the loggingOptions() top level:

loggingOptions({
  level: "option",
  formatter: "--log-format",
})

That placement is intentional. The formatter affects the generated sink, not only the --log-output destination option. It also keeps formatter parsing available when output.enabled is false, while fixed formatter values still apply to the default console output.

How it works

textFormatter() accepts jsonl, logfmt, color, and plain, returning LogTape's jsonLinesFormatter, logfmtFormatter, ansiColorFormatter, and defaultTextFormatter.

logOutput() now accepts formatter?: string | TextFormatter. A string adds a formatter option such as --log-format; a TextFormatter applies a fixed formatter to whichever output the user selects.

createSink() now passes formatter values through to both console and file sinks. The console path still lets explicit ConsoleSinkOptions.formatter override a formatter carried by LogOutput, so call-site sink configuration remains the final say.

The docs in docs/integrations/logtape.md and packages/logtape/README.md show both forms, and packages/core/skills/optique/SKILL.md now describes the LogTape integration as covering formatter/output options.

Verification

The branch has been checked with:

  • mise test:deno packages/logtape
  • pnpm --filter @optique/logtape build
  • pnpm --filter @optique/logtape test
  • pnpm --filter @optique/logtape test:bun
  • pnpm build in docs/
  • mise check

dahlia added 3 commits July 3, 2026 02:32
Allow createConsoleSink() to accept LogTape text and console
formatters while preserving Optique's existing stream routing and
default console output format.  Text formatter output follows LogTape's
console sink behavior by trimming a trailing line ending before calling
the selected console method.

Update the LogTape integration docs to show logfmtFormatter and refresh
LogTape dependency locks so the documented formatter is available during
Twoslash and package checks.

#867

Assisted-by: Codex:gpt-5.5
Add textFormatter() for mapping jsonl, logfmt, color, and plain
CLI values to LogTape's built-in text formatter functions.  Export the
parser from @optique/logtape and cover parsing, suggestions, formatting,
and option integration.

Document the new parser in the LogTape integration guide, package README,
parser catalog, changelog, and Optique agent skill.

#867

Assisted-by: Codex:gpt-5.5
Log output parsers now carry parsed or fixed LogTape text formatters
through the LogOutput value, so createSink() can apply the selected
format to both console and file sinks.

The loggingOptions() preset exposes formatter at the top level because
it configures the generated sink rather than only the output destination
option.

#867

Assisted-by: Codex:gpt-5.5
@dahlia dahlia added this to the Optique 1.2 milestone Jul 2, 2026
@dahlia dahlia self-assigned this Jul 2, 2026
@dahlia dahlia added the enhancement New feature or request label Jul 2, 2026
@dahlia

dahlia commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.41%. Comparing base (747f36a) to head (60a64f0).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/logtape/src/output.ts 98.52% 0 Missing and 1 partial ⚠️
packages/logtape/src/preset.ts 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #867   +/-   ##
=======================================
  Coverage   93.41%   93.41%           
=======================================
  Files          75       76    +1     
  Lines       38503    38567   +64     
  Branches     9578     9593   +15     
=======================================
+ Hits        35967    36028   +61     
  Misses       1733     1733           
- Partials      803      806    +3     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request upgrades the LogTape dependencies to version 2.2.2 and introduces support for custom text formatters. It adds a new textFormatter() value parser to map string identifiers to LogTape's built-in formatters, and integrates a formatter option into logOutput() and loggingOptions(). Additionally, createConsoleSink() and createSink() have been updated to support custom formatters, accompanied by comprehensive documentation updates and unit tests. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: e7424813a1

ℹ️ 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".

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ef9a5d9b-5f15-4c1d-a0e2-4079364cb804

📥 Commits

Reviewing files that changed from the base of the PR and between 6dcaa65 and 60a64f0.

📒 Files selected for processing (2)
  • packages/logtape/src/index.test.ts
  • packages/logtape/src/output.ts

Walkthrough

This PR adds formatter customization support to the @optique/logtape package. A new textFormatter() parser maps CLI formatter names to LogTape formatter functions, and formatter options are threaded through LogOutput, ConsoleSinkOptions, logOutput(), createConsoleSink(), createSink(), and loggingOptions(). Supporting changes include expanded tests, documentation updates, changelog updates, and dependency version bumps for @logtape/file and @logtape/logtape to ^2.2.2.

Estimated code review effort: 4 (Complex) | ~50 minutes

Possibly related PRs

  • dahlia/optique#707: Both PRs modify packages/logtape/src/output.ts’s createConsoleSink().
  • dahlia/optique#852: Both PRs update the Optique skill docs and tests around the LogTape package entry.

Suggested labels: documentation, enhancement, logtape

Suggested reviewers: dahlia

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding formatter selection support for LogTape.
Description check ✅ Passed The description is directly related to the changeset and accurately explains the formatter-selection flow and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch packages/logtape/formatters

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/logtape/src/index.test.ts`:
- Around line 1052-1137: The console.log mock/restore pattern is duplicated in
multiple createConsoleSink tests, so extract a shared helper or switch to
node:test’s t.mock.method(console, "log") to centralize setup and auto-restore.
Update the affected tests around createConsoleSink to use that helper instead of
manually saving originalLog, assigning console.log, and wrapping each call in
try/finally.

In `@packages/logtape/src/preset.ts`:
- Around line 340-347: The formatter option parsing is duplicated between
preset.ts and output.ts’s withFormatter(), so the two implementations can drift.
Extract the shared optional(option(..., textFormatter(), { description:
message`Log output format.` })) construction into a small helper in output.ts,
then reuse that helper from the outputFormatter string branch in preset.ts and
from withFormatter() so the parsing logic stays in one place.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f1cd8a73-aa1e-4540-b4b5-81c867ac0469

📥 Commits

Reviewing files that changed from the base of the PR and between 747f36a and e742481.

⛔ Files ignored due to path filters (2)
  • deno.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • CHANGES.md
  • deno.json
  • docs/.vitepress/theme/components/ParserCatalog.vue
  • docs/index.md
  • docs/integrations/logtape.md
  • packages/core/skills/optique/SKILL.md
  • packages/core/skills/optique/SKILL.test.ts
  • packages/logtape/README.md
  • packages/logtape/deno.json
  • packages/logtape/src/index.test.ts
  • packages/logtape/src/index.ts
  • packages/logtape/src/output.ts
  • packages/logtape/src/preset.ts
  • packages/logtape/src/textformatter.ts
  • pnpm-workspace.yaml

Comment thread packages/logtape/src/index.test.ts
Comment thread packages/logtape/src/preset.ts
The formatter option parser now lives in one place, so the preset and
logOutput() cannot drift in option names, descriptions, or value parsing.
The console sink tests also share a small capture helper instead of
repeating manual console.log restore blocks.

#867 (comment)
#867 (comment)

Assisted-by: Codex:gpt-5.5
@dahlia

dahlia commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces customizable text formatting capabilities to the @optique/logtape package. It adds a new textFormatter() value parser to map formatter names (jsonl, logfmt, color, plain) to LogTape's built-in formatters, and integrates a formatter option into logOutput(), loggingOptions(), createConsoleSink(), and createSink(). Additionally, it upgrades @logtape/file and @logtape/logtape dependencies to version 2.2.2 and updates the relevant documentation and test suites. There are no review comments provided, so I have no feedback to address.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/logtape/src/output.ts`:
- Around line 260-268: The newly exported createTextFormatterOption function is
missing required JSDoc. Add a JSDoc block above createTextFormatterOption
describing its purpose, the long parameter, the returned
FluentParser/TextFormatter option, and include an `@throws` note for invalid
option names propagated through option().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7c124122-7c26-4a18-a430-f6c9de70e676

📥 Commits

Reviewing files that changed from the base of the PR and between e742481 and 2563cc6.

📒 Files selected for processing (3)
  • packages/logtape/src/index.test.ts
  • packages/logtape/src/output.ts
  • packages/logtape/src/preset.ts

Comment thread packages/logtape/src/output.ts
The shared formatter option helper is exported for use by the preset,
so it should carry the same API documentation as the rest of the
package surface.

#867 (comment)

Assisted-by: Codex:gpt-5.5
@dahlia

dahlia commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@dahlia

dahlia commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces text formatting capabilities to the @optique/logtape package, adding a new textFormatter() value parser and integrating a formatter option into logOutput(), loggingOptions(), and createConsoleSink(). The review feedback highlights a potential runtime error in toConsoleArgs if a custom formatter returns an unexpected type, suggesting explicit array validation to ensure robust argument spreading.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/logtape/src/output.ts Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 6dcaa6541c

ℹ️ 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".

Custom formatter callbacks can still return unexpected values at
runtime, especially from plain JavaScript callers.  Normalize those
values before spreading them into console methods so invalid returns do
not turn into console sink failures.

#867 (comment)

Assisted-by: Codex:gpt-5.5
@dahlia

dahlia commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for custom text and console formatters in the @optique/logtape package. It adds a new textFormatter() value parser to map string identifiers ("jsonl", `

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@dahlia

dahlia commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 60a64f0826

ℹ️ 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".

@dahlia
dahlia merged commit 7836254 into main Jul 3, 2026
8 checks passed
@dahlia
dahlia deleted the packages/logtape/formatters branch July 3, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant