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

Export non-patched console #46

Open
sambuccid opened this issue Jul 10, 2024 · 3 comments
Open

Export non-patched console #46

sambuccid opened this issue Jul 10, 2024 · 3 comments

Comments

@sambuccid
Copy link

First of all thank you for this great library, I wouldn't be able to use Next without it.

I was wondering if it would be possible to export an unpatched version of the console when we patch it.

It would be very useful for specific edge cases where we need to output something to the console without wanting to format it.

My specific use case is with nextjs middleware.
The middleware forces the use of the "browser" version of pino, and this redirects all logs to the console.

This creates nested logs where the string logged is inside a log that is then sent by pino to the console and re-wrapped by next-logger.

With access to the original unpatched version of the console it would be possible to change this so that after the logs is processed by pino in my application they are sent directly to the console without passing through next-logger.

@atkinchris
Copy link
Collaborator

What would be the most ergonomic way for you to consume this? Extra methods, or an exported originalConsole/unpatchedConsole?

@sambuccid
Copy link
Author

sambuccid commented Jul 12, 2024 via email

@gustafc
Copy link

gustafc commented Dec 18, 2024

I've run into this problem, too. Easiest workaround seems to be just using console.{debug,log,warn,error} in the middleware, but it'd be nice being able to set log levels etc - especially since middlewares usually handle some really important tasks, like authentication.

Not sure how exposing an unpatchedConsole would work though, since you can't import next-logger in middlewares (crashes with "The edge runtime does not support Node.js 'fs' module").

Another approach would be an option to pass through lines which seem to already be JSON, either determined by some ugly heuristic like line.startsWith('{') && line.endsWith('}'), by full-blown JSON parsing, something in between, or allowing a caller-defined function.

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