-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Describe the feature you'd like to request
Motivation:
Better nextjs logging (especially for unhandled exceptions) to understand exactly context of possible errors/warnings and be able to respond very fast to those situations.
Hi, right now after next build when we start next server with next start we see output logs only if error happens.
I would like to be able to have more control here over
- log format. Example print json output instead of line by line example that i copy below
Error: {"size":0,"timeout":0}
at getStaticProps (/usr/src/app/.next/server/pages/post/[id].js:3576:11)
at runMicrotasks (<anonymous>)
- Ability to add meta/context to nextjs logs after specifying a json format. Example enrich all logs with request url as well, or with custom tracing field whatever developer wants.
In that case above log would look like {"message": "some message here", "url": "domain.com/someurl", "appVersion":"something", ...othermeta} - In above real log that I posted i see js file name, but my code is in typescript. How can we apply source maps so see ts file line in log output in those unhandled errors ?
PS: This is not about wrapping everything in a try catch and logging to custom logger. We are doing that sending to newrelic, but many things happen and are not handled. In those cases next server prints the error but without formatting context and is not very useful, therefore my suggestion to having a great way like in other frameworks for full visibility
Describe the solution you'd like
As described in feature request I want to be able to do those actions.
I think one way maybe can be configurations in next.config.js but as I don't know nextjs internals well I am open to any solution that is best fit
Describe alternatives you've considered
Unfortunately nothing because is impossible currently to add meta and format next output to json.