Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/workerd-logger-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"effect": patch
---

fix(Logger): Support Cloudflare Workers by treating workerd as TTY environment

Fixes missing log messages in Cloudflare Workers where console.group methods are no-ops.

The pretty logger now:
- Detects workerd runtime using `navigator.userAgent === 'Cloudflare-Workers'`
- Routes workerd to TTY logger mode instead of browser mode
- Disables console.group calls in workerd (similar to existing Bun handling)

This ensures all log messages display correctly in Cloudflare Workers local development.
9 changes: 6 additions & 3 deletions packages/effect/src/internal/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ const hasProcessStdout = typeof process === "object" &&
process.stdout !== null
const processStdoutIsTTY = hasProcessStdout &&
process.stdout.isTTY === true
const isWorkerd = typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers"
const hasProcessStdoutOrDeno = hasProcessStdout || "Deno" in globalThis
const shouldUseTTYMode = hasProcessStdoutOrDeno || isWorkerd

/** @internal */
export const prettyLogger = (options?: {
Expand All @@ -342,7 +344,7 @@ export const prettyLogger = (options?: {
readonly mode?: "browser" | "tty" | "auto" | undefined
}) => {
const mode_ = options?.mode ?? "auto"
const mode = mode_ === "auto" ? (hasProcessStdoutOrDeno ? "tty" : "browser") : mode_
const mode = mode_ === "auto" ? (shouldUseTTYMode ? "tty" : "browser") : mode_
const isBrowser = mode === "browser"
const showColors = typeof options?.colors === "boolean" ? options.colors : processStdoutIsTTY || isBrowser
const formatDate = options?.formatDate ?? defaultDateFormat
Expand All @@ -357,6 +359,7 @@ const prettyLoggerTty = (options: {
readonly formatDate: (date: Date) => string
}) => {
const processIsBun = typeof process === "object" && "isBun" in process && process.isBun === true
const supportsConsoleGroup = !processIsBun && !isWorkerd
const color = options.colors ? withColor : withColorNoop
return makeLogger<unknown, void>(
({ annotations, cause, context, date, fiberId, logLevel, message: message_, spans }) => {
Expand Down Expand Up @@ -389,7 +392,7 @@ const prettyLoggerTty = (options: {
}

log(firstLine)
if (!processIsBun) console.group()
if (supportsConsoleGroup) console.group()

if (!Cause.isEmpty(cause)) {
log(Cause.pretty(cause, { renderErrorCause: true }))
Expand All @@ -407,7 +410,7 @@ const prettyLoggerTty = (options: {
}
}

if (!processIsBun) console.groupEnd()
if (supportsConsoleGroup) console.groupEnd()
}
)
}
Expand Down