next-logger icon indicating copy to clipboard operation
next-logger copied to clipboard

Is There a Way to Handle process.stdout.write?

Open CHC383 opened this issue 8 months ago • 3 comments

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 the msg 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.

CHC383 avatar Jun 10 '24 19:06 CHC383