Pino logger does not output JSON within NextJS middleware function #33898
Replies: 9 comments 10 replies
-
I have a similar issue, but ours is pretty-printing JSON and it's driving me crazy:
comes out as
(which is not even technically JSON, it's just a pretty-printed js object) and it's kind of driving me crazy. Anyone know how to turn this off? |
Beta Was this translation helpful? Give feedback.
-
Having the same issue, in our case Data Dog consumes each line as new log message. |
Beta Was this translation helpful? Give feedback.
-
Having the same issue while using pino logger in middleware, but I'm trying to output the log in server. |
Beta Was this translation helpful? Give feedback.
-
Same issue here. I ended up writing a small wrapper to JSON stringify the error and add a
|
Beta Was this translation helpful? Give feedback.
-
Any updates on this issue? I am having the same problem: none of the logs created in my NextJS middlleware are formatted as JSON. Pino-pretty is not working as well. 😢 |
Beta Was this translation helpful? Give feedback.
-
How is everyone using pino from the middleware at all? I get the |
Beta Was this translation helpful? Give feedback.
-
how about this one? pino({
browser: {
write: (o) => console.log(JSON.stringify(o)),
},
}).info('Pino info log from middleware');
pino({
browser: {
write: (o) => console.log(JSON.stringify(o)),
},
}).error('Pino error log from middleware');
pino({
browser: {
write: (o) => console.log(JSON.stringify(o)),
},
}).fatal('Pino fatal log from middleware');
const logger = pino({
browser: {
write: (o) => console.log(JSON.stringify(o)),
},
});
logger.child({ '1': '2', '3': '4' }).info('Pino info log from middleware'); |
Beta Was this translation helpful? Give feedback.
-
To add some context here, the NextJS middleware runs in the edge runtime, which effects more than just |
Beta Was this translation helpful? Give feedback.
-
Has anyone tested this in Next.js 14? |
Beta Was this translation helpful? Give feedback.
-
I was planning to use Pino logger within NextJS middleware function:
pages/_middleware.ts
Then when I run
next dev
and request the page, log in no JSON format is printed out:Weirdly when I use the same logging within any page component:
Pino logs in JSON format:
Not sure what's going. Does NextJS somehow reformat output coming out from middleware functions? 🤔 The same happens for production build with
NODE_ENV=production
.Beta Was this translation helpful? Give feedback.
All reactions