Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CHC383 opened this issue Jun 10, 2024 · 3 comments
Open

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

CHC383 opened this issue Jun 10, 2024 · 3 comments

Comments

@CHC383
Copy link

CHC383 commented Jun 10, 2024

Starting from Next 14.2.0, Next will output request logs in dev mode (vercel/next.js#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.

@devinrhode2
Copy link

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.

@atkinchris
Copy link
Collaborator

We really need first-class support for JSON logging in Next.js itself. 😅

@CHC383
Copy link
Author

CHC383 commented Jun 26, 2024

We really need first-class support for JSON logging in Next.js itself. 😅

There is a discussion on the Next.js side: vercel/next.js#63787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants