Open CHC383 opened 1 month ago
Patch-package next itself would probably work. Maybe a postinstall that does a sort-of search and replace - Biome.js uses a nifty library for doing search-and-replace type commands.
Although it's probably just as easy to get a PR merged into core, which allows for doing these logging things.
Lastly, sentry has a fine logging solution for next, so they will certainly have a solution on their sdk.
Good luck.
We really need first-class support for JSON logging in Next.js itself. 😅
We really need first-class support for JSON logging in Next.js itself. 😅
There is a discussion on the Next.js side: https://github.com/vercel/next.js/discussions/63787
Starting from Next 14.2.0, Next will output request logs in dev mode (https://github.com/vercel/next.js/pull/62946), which is always enabled and uses
process.stdout.write
to output the logs.I tried to create a new patch for
process.stdout.write
but realized that Pino also uses the same method underneath by default (I believed it is this code). Even though during the testing this recursive calling loop seems to work, but the output is not as expected, i.e. the whole JSON format message is wrapped in themsg
field, instead of itself being the output.One potential hacky workaround is to check the caller and decide whether we need to patch the call or not, but Function.prototype.caller is deprecated due to security risks, so this doesn't seem to be a viable path.
I wonder if there are any other solutions, or it just can't be solved.