Skip to content

Conversation

schickling
Copy link
Contributor

Summary

Fixes the pretty logger for Cloudflare Workers where console.group/console.groupCollapsed are no-ops, causing log messages to disappear.

Problem

In Cloudflare Workers (workerd runtime):

  • console.group(), console.groupCollapsed(), and console.groupEnd() are no-ops
  • When Logger.pretty tries to use these methods, the first log message gets "consumed" by the no-op call and disappears
  • This results in missing log output, especially for single-argument Effect.log() calls

Solution

  • Add workerd runtime detection using navigator.userAgent === 'Cloudflare-Workers'
  • Modify prettyLoggerTty to skip console.group() calls in workerd (similar to existing Bun handling)
  • Modify prettyLoggerBrowser to use flat logging instead of console.groupCollapsed() in workerd
  • Preserve all existing functionality for other runtimes

Testing

Tested with a Cloudflare Worker using the modified Effect logger:

  • ✅ Multi-argument logs now display all messages: Effect.log("First", "second", "third")
  • ✅ Single-argument logs no longer disappear: Effect.log("Single test")
  • ✅ All log levels work correctly
  • ✅ Annotations and spans still display properly

Related Issues

Closes #5398

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

…n in workerd

- Add workerd runtime detection using navigator.userAgent === 'Cloudflare-Workers'
- Modify prettyLoggerTty to skip console.group/groupEnd in workerd (similar to Bun)
- Modify prettyLoggerBrowser to use flat logging instead of console.groupCollapsed in workerd
- Fixes missing log messages in Cloudflare Workers where console.group methods are no-ops

Resolves Effect-TS#5398
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Aug 24, 2025
Copy link

changeset-bot bot commented Aug 24, 2025

🦋 Changeset detected

Latest commit: 434e834

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
effect Patch
@effect/cli Patch
@effect/cluster Patch
@effect/experimental Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/platform Patch
@effect/printer-ansi Patch
@effect/printer Patch
@effect/rpc Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-drizzle Patch
@effect/sql-kysely Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/sql Patch
@effect/typeclass Patch
@effect/vitest Patch
@effect/workflow Patch
@effect/ai Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-google Patch
@effect/ai-openai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

… browser logger

- Detect workerd as TTY environment using shouldUseTTYMode logic
- Route workerd to TTY logger which already has console.group detection
- Keep browser logger unchanged for actual browser environments
- Add changeset documenting the fix
- Reuse module-level isWorkerd constant instead of redefining in prettyLoggerTty
- Cleaner code with single source of truth for workerd detection
@mikearnaldi mikearnaldi requested a review from tim-smart August 26, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Discussion Ongoing
Development

Successfully merging this pull request may close these issues.

Logger.pretty drops first argument in Cloudflare Workers
1 participant