Skip to content

fix: pipe Next.js server stdout/stderr to debug log file#15065

Open
thesandlord wants to merge 1 commit intomainfrom
devin/1776277156-pipe-nextjs-stderr-to-debug-log
Open

fix: pipe Next.js server stdout/stderr to debug log file#15065
thesandlord wants to merge 1 commit intomainfrom
devin/1776277156-pipe-nextjs-stderr-to-debug-log

Conversation

@thesandlord
Copy link
Copy Markdown
Contributor

Description

Refs: Related to fern-api/fern-platform#9752

Previously, the Next.js standalone server's stdout/stderr was only sent to context.logger.debug(), which does not write to the ~/.fern/logs/*.debug.log file. This made it impossible to diagnose server-side errors (e.g. 500 responses, module resolution failures) from the debug log — only CLI-level structured events (reload, validation, memory) appeared there.

Changes Made

  • Added DebugLogger.logServerOutput(stream, text) method that writes structured JSON entries with source: "nextjs-server" and appropriate log levels ("error" for stderr, "debug" for stdout)
  • Wired up all four server output channels in runAppPreviewServer.ts to write to the debug log:
    • stdout data (the checkReady handler)
    • stderr data
    • Process error events
    • Process exit events
  • Added "nextjs_server_output" to the CliMetricEvent type union

All calls use void (fire-and-forget) to avoid blocking server operation, matching the existing pattern for other debug logger calls.

Review Checklist

  • "nextjs_server_output" was added to CliMetricEvent.type, but logServerOutput writes directly via writeEntry rather than going through logCliMetric — the type union addition is not strictly necessary. Confirm this is acceptable or should be removed.
  • Verify that high-volume stdout (e.g. during SSR of many pages) won't cause excessive disk writes or performance issues via the fire-and-forget appendFile calls.

Testing

  • Manual testing not feasible in this environment (requires Windows + fern docs dev)
  • Lint passes (pnpm run check)
  • No unit tests added — this is a logging-only change with no behavioral impact on the server itself

Link to Devin session: https://app.devin.ai/sessions/384de2d2e741453fa07377d662b6e2c2
Requested by: @thesandlord

Previously, the Next.js standalone server output was only piped to
context.logger.debug() which does not write to the .debug.log file.
This made it impossible to diagnose server-side errors (e.g. 500s)
from the debug log.

Now, all stdout, stderr, process errors, and exit events from the
Next.js server are written to the debug log via DebugLogger.logServerOutput().
This gives full visibility into server startup failures, rendering errors,
and module resolution issues — especially useful for diagnosing Windows
compatibility problems.

Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant