Better monitoring / Improvements in nextjs server stdout (logs) output #35360
Replies: 5 comments 3 replies
-
|
Another example that is real life causing trouble for me to understand where and how error happens. I don't know where that error happens or in what context. That entire message could be json, and allow for adding extra meta like I am quite confident that you guys can implement this easily and hopefully this post gets visibility. |
Beta Was this translation helpful? Give feedback.
-
|
I would also like this functionality. Enabling the developer to have fine-grained control over the applications output is important for monitoring integrations. All of my logs are output in JSON everywhere except for server-side errors in NextJS. This is disruptive when looking at logs for a request in most log explorers, since each line of the stack trace are on different lines. I have been able to mitigate this by implementing my own HoF for |
Beta Was this translation helpful? Give feedback.
-
|
I agree this seems to me something that would be needed for proper logging. |
Beta Was this translation helpful? Give feedback.
-
|
I've found a workaround if you're using a custom server, albeit it's somewhat hacky and not guaranteed to work in future versions. type ExposedNextServer = Omit<NextServer, 'getServer'> & {
getServer: () => Promise<ExposedNextServer>;
quiet?: boolean;
};
async function createNextServer() {
const server = next({}) as unknown as ExposedNextServer;
const innerServer = await server.getServer();
if (!(innerServer.logError instanceof Function)) {
throw Error('Expected NextServer.logError to be a function');
}
innerServer.logError = (err: Error) => {
if (innerServer.quiet) return;
logger.error(err, 'NextJSError');
};
return server;
}All said and done, this logError implementation is the exact same as what exists in NextJS currently, with the logger method replaced |
Beta Was this translation helpful? Give feedback.
-
|
Our usecase is that we have Datadog agent listening on stderr for logs. If they are json, they are parsed, if they are plaintext, they get logged per-line. So now even if we log to JSON in the app, any uncaught exception still pass through and is logged as lines effectively preventing any meaningful correlation effort in datadog. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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 buildwhen we start next server withnext startwe see output logs only if error happens.I would like to be able to have more control here over
In that case above log would look like {"message": "some message here", "url": "domain.com/someurl", "appVersion":"something", ...othermeta}
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.
Beta Was this translation helpful? Give feedback.
All reactions