Skip to content

fix(nitro): allow useLogger() in server middleware#215

Merged
HugoRCD merged 2 commits intomainfrom
fix/nitro-middleware
Mar 21, 2026
Merged

fix(nitro): allow useLogger() in server middleware#215
HugoRCD merged 2 commits intomainfrom
fix/nitro-middleware

Conversation

@HugoRCD
Copy link
Copy Markdown
Owner

@HugoRCD HugoRCD commented Mar 21, 2026

🔗 Linked issue

Resolves #210

📚 Description

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@HugoRCD HugoRCD self-assigned this Mar 21, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 Mar 21, 2026 0:32am

@HugoRCD HugoRCD requested a review from Copilot March 21, 2026 11:14
@github-actions github-actions bot added the bug Something isn't working label Mar 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 21, 2026

Thank you for following the naming conventions! 🙏

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 21, 2026

Benchmark report

Bundle size

Threshold: 5% · 🔴 larger · 🟡 warning · 🟢 smaller · ⚪ unchanged · 🆕 new

Status Entry Base (gzip) Current (gzip) Change Raw delta
framework/nitro 6.85 kB 6.87 kB +0.4% +155 B
logger 3.78 kB 3.78 kB 0.0% 0 B
framework/next 3.02 kB 3.02 kB 0.0% 0 B
framework/vite 2.38 kB 2.38 kB 0.0% 0 B
adapter/sentry 2.34 kB 2.34 kB 0.0% 0 B
adapter/otlp 2.10 kB 2.10 kB 0.0% 0 B
framework/ai 1.98 kB 1.98 kB 0.0% 0 B
enrichers 1.92 kB 1.92 kB 0.0% 0 B
framework/sveltekit 1.54 kB 1.54 kB 0.0% 0 B
adapter/posthog 1.50 kB 1.50 kB 0.0% 0 B
adapter/fs 1.41 kB 1.41 kB 0.0% 0 B
utils 1.41 kB 1.41 kB 0.0% 0 B
pipeline 1.35 kB 1.35 kB 0.0% 0 B
adapter/axiom 1.32 kB 1.32 kB 0.0% 0 B
browser 1.21 kB 1.21 kB 0.0% 0 B
error 1.21 kB 1.21 kB 0.0% 0 B
framework/nestjs 1.21 kB 1.21 kB 0.0% 0 B
adapter/better-stack 1.09 kB 1.09 kB 0.0% 0 B
framework/fastify 1009 B 1009 B 0.0% 0 B
workers 960 B 960 B 0.0% 0 B
framework/express 701 B 701 B 0.0% 0 B
framework/hono 594 B 594 B 0.0% 0 B
toolkit 242 B 242 B 0.0% 0 B
core (index) 205 B 205 B 0.0% 0 B
client 118 B 118 B 0.0% 0 B
types 31 B 31 B 0.0% 0 B
framework/elysia 1.07 kB 1.05 kB -1.7% -29 B
Total 42.45 kB 42.46 kB +0.0% +126 B

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 21, 2026

npm i https://pkg.pr.new/evlog@215
npm i https://pkg.pr.new/@evlog/nuxthub@215

commit: 95afa99

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Nitro/Nuxt server middleware compatibility by ensuring a request-scoped evlog logger is always attached to the event context (so useLogger(event) won’t throw), while still honoring route include/exclude filtering at emit time.

Changes:

  • Always create the request logger in Nitro v2/v3 request hooks, storing a new _evlogShouldEmit flag for later guards.
  • Skip emission in afterResponse/response and error hooks when _evlogShouldEmit is false.
  • Add a changeset and new tests aimed at covering the middleware scenario.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/evlog/src/nitro/plugin.ts Always creates logger; adds _evlogShouldEmit and uses it to guard emission in hooks.
packages/evlog/src/nitro-v3/plugin.ts Same behavior for Nitro v3 plugin (request always creates logger; response/error gated).
packages/evlog/src/types.ts Adds _evlogShouldEmit?: boolean to H3EventContext.
packages/evlog/test/nitro-plugin.test.ts Adds new “middleware compatibility” tests (currently not effectively exercising the plugin).
.changeset/fix-middleware-uselogger.md Patch release note describing the behavioral change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Address Copilot review feedback: the previous tests were tautological
(manually setting values and asserting them back). New tests replicate
the plugin's request/afterResponse/error hook logic and invoke it
against real createRequestLogger instances, verifying observable
behavior (logger creation, emit gating, error propagation).
@HugoRCD HugoRCD merged commit 31cb4ab into main Mar 21, 2026
12 of 14 checks passed
@HugoRCD HugoRCD deleted the fix/nitro-middleware branch March 21, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Unable to use evlog in nuxt server middleware

2 participants