Skip to content

feat: introduce pino structured logger#48

Merged
jellydn merged 1 commit into
mainfrom
feat/logger
Jun 18, 2026
Merged

feat: introduce pino structured logger#48
jellydn merged 1 commit into
mainfrom
feat/logger

Conversation

@jellydn

@jellydn jellydn commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Introduces structured server-side logging with pino, replacing ad-hoc console.log / console.error calls.

What

  • New server/lib/logger.ts — single configurable logger (env-driven LOG_LEVEL, pino-pretty in dev, silent in tests).
  • Wires the logger into server/deploy.ts and the magic-link sender, the earliest sites where unstructured logs hurt debugging.
  • Adds pino + pino-pretty to package.json + bun.lock.

Why split

Logger is the foundation for the rest of #47 (the proxy 502 observability fix and the logHandlerFailure helper both depend on server/lib/logger.ts). Splitting it out as the bottom of the stack keeps the diff for #47 focused on file splits, DB cleanup, and the helper — not "introduce logger + first consumer + first helper" all at once.

Test plan

  • bun run typecheck → 0 errors
  • bun run test → all tests pass

Summary by CodeRabbit

  • Chores
    • Introduced structured logging infrastructure with enhanced error handling and monitoring capabilities. Error reporting and application logging have been standardized across deployment processes and email authentication services. The new logging system includes environment-aware log levels and colorized output formatting in development environments for improved developer experience, alongside enhanced observability for production environments.

- Add pino and pino-pretty as dependencies
- Create server/lib/logger.ts with pino (pretty printing in dev,
  JSON in production, configurable LOG_LEVEL)
- Replace console.error in server/deploy.ts with logger.error
  (audit log write failures)
- Replace console.log/error in server/lib/send-magic-link-email.ts
  with logger.info/error (dev magic link fallback + Resend errors)
@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2e3195d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1546fab-c2dc-4945-ad08-dd5d68644443

📥 Commits

Reviewing files that changed from the base of the PR and between 3d71ffc and 2e3195d.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • package.json
  • server/deploy.ts
  • server/lib/logger.ts
  • server/lib/send-magic-link-email.ts

Walkthrough

Adds pino and pino-pretty as dependencies and introduces server/lib/logger.ts with a single exported pino logger instance configured by NODE_ENV and LOG_LEVEL. Existing console.log/console.error calls in server/deploy.ts and server/lib/send-magic-link-email.ts are replaced with structured logger.error/logger.info calls.

Changes

Structured Logging via Pino

Layer / File(s) Summary
Logger module and dependencies
package.json, server/lib/logger.ts
Adds pino and pino-pretty to dependencies and creates server/lib/logger.ts exporting a pino instance with log level derived from NODE_ENV/LOG_LEVEL and pino-pretty transport enabled outside production.
Migrate console calls to logger
server/deploy.ts, server/lib/send-magic-link-email.ts
Imports logger in both modules; replaces console.error audit-log failure calls in deploy.ts with logger.error (normalizing non-Error values), and replaces console.log/console.error in sendMagicLinkEmail with structured logger.info/logger.error calls.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Hoppity-hop, no more console noise,
Pino swoops in with structured joys!
Production goes quiet, dev gets color bright,
Every error logged with fields just right.
The rabbit approves—such tidy delight! 🪵

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: introducing pino structured logger as the primary objective of this pull request.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/logger

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 and usage tips.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

React Doctor found no issues. 🎉

Reviewed by React Doctor for commit 2e3195d.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpino-pretty@​13.1.39910010086100
Addedpino@​10.3.19910010090100

View full report

@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 structured logging by adding pino and pino-pretty dependencies and replacing standard console logging calls with a centralized logger utility in server/deploy.ts and server/lib/send-magic-link-email.ts. The reviewer noted that the logger should be configured to be silent during tests to avoid flooding the test output with verbose logs, and provided a code suggestion to handle the "test" environment.

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 server/lib/logger.ts
Comment on lines +3 to +15
const isProduction = process.env.NODE_ENV === "production";

export const logger = pino({
level: process.env.LOG_LEVEL ?? (isProduction ? "info" : "debug"),
...(isProduction
? {}
: {
transport: {
target: "pino-pretty",
options: { colorize: true },
},
}),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The pull request description states that the logger should be "silent in tests". However, the current implementation only checks isProduction and defaults to "debug" with pino-pretty enabled when NODE_ENV is not "production" (which includes "test"). This will flood the test output with verbose logs.

We should explicitly check if the environment is "test" and default the log level to "silent" while disabling the pretty transport.

Suggested change
const isProduction = process.env.NODE_ENV === "production";
export const logger = pino({
level: process.env.LOG_LEVEL ?? (isProduction ? "info" : "debug"),
...(isProduction
? {}
: {
transport: {
target: "pino-pretty",
options: { colorize: true },
},
}),
});
const isProduction = process.env.NODE_ENV === "production";
const isTest = process.env.NODE_ENV === "test";
export const logger = pino({
level: process.env.LOG_LEVEL ?? (isTest ? "silent" : isProduction ? "info" : "debug"),
...(isProduction || isTest
? {}
: {
transport: {
target: "pino-pretty",
options: { colorize: true },
},
}),
});

@jellydn jellydn marked this pull request as ready for review June 18, 2026 00:45
@jellydn

jellydn commented Jun 18, 2026

Copy link
Copy Markdown
Owner Author

cc @jellydn — requesting a quick sign-off on the logger API surface before this lands. PR #47 stacks on top of this and imports server/lib/logger.ts via its new logHandlerFailure helper, so this PR should merge first.

API contract (server/lib/logger.ts)

  • Default export: a pre-configured logger instance (pino).
  • Default level: info in production (NODE_ENV=production), debug otherwise.
  • Override: LOG_LEVEL env var wins over the default (e.g. LOG_LEVEL=warn).
  • Pretty-printing: uses pino-pretty in non-production; raw JSON in production.
  • No callers depend on anything beyond logger.info | warn | error | debug | fatal.

Consumers wired in this PR

  • server/lib/send-magic-link-email.ts — replaced the previous console.error(...) in the catch path with logger.error({ event, err }, msg).

The wider rollout (13 silent-catch sites catalogued in CONCERNS.md) ships in PR #47 via the new server/lib/handler-error-log.ts helper.

Please confirm

  1. LOG_LEVEL is the right env-var convention going forward.
  2. Default-level policy (info prod / debug dev + pretty) is acceptable.
  3. The schema (no logger.fatal callers expected, no streaming transports) is fine for the planned rollout sites.

Diff is 3 files: server/lib/logger.ts (new) + server/lib/send-magic-link-email.ts + package.json. 107 server tests / 792 total pass on feat/logger standalone.

@jellydn jellydn merged commit 81c878a into main Jun 18, 2026
9 checks passed
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.

1 participant