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

Next 13 compatibility #22

Closed
arichard-info opened this issue Nov 27, 2023 · 4 comments
Closed

Next 13 compatibility #22

arichard-info opened this issue Nov 27, 2023 · 4 comments

Comments

@arichard-info
Copy link

Hello !

It seems that next-logger is not working properly since Next 13.4.20 : vercel/next.js#54713
I may propose a PR when I have the time, but for now let's describe the issue.

The Next log format has changed, for example :

Now :
image

Before :
image

Since next-logger relies on logs prefixes, we now have log format errors :

Initial log :

⚠ See more info here: https://nextjs.org/docs/messages/invalid-next-config
✓ Ready in 1626ms

Formatted log with next-logger :

{"level":40,"time":1701102955852,"pid":35967,"hostname":"myhostname","name":"console","msg":" \u001b[33m\u001b[1m⚠\u001b[22m\u001b[39m See more info here: https://nextjs.org/docs/messages/invalid-next-config"}
{"level":30,"time":1701102956877,"pid":35967,"hostname":"myhostname","name":"console","msg":" \u001b[32m\u001b[1m✓\u001b[22m\u001b[39m Ready in 1637ms"}

The new log format is going to be complicated to format. Now there are multi-lines and special characters 😕

@rslowinski
Copy link

any updates on this topic? :)

@atkinchris
Copy link
Collaborator

atkinchris commented Feb 21, 2024

I've been digging into this with Next 14, and I'm hitting a blocker. The chalk prefixes shouldn't be an issue, as once patched, we don't call those internal methods at all.

However, patching is my blocker at this stage. An as const declaration was added to Next's log prefixes.

Currently, we patch the prefix methods with basic assignment:

Object.keys(nextLogger.prefixes).forEach(method => {
  nextLogger[method] = getPinoMethod(method)
})

With as const, these methods now only have getters - and silently refuse the assignment, so patching does nothing. Neither Object.assign nor Object.defineProperty can work around this either, by design.

Object.assign(nextLogger, { [method]: getPinoMethod(method) })
// TypeError: Cannot set property XXX of #<Object> which has only a getter

Object.defineProperty(nextLogger, method, { value: getPinoMethod(method) })
// TypeError: Cannot redefine property: XXX

I'm investigating if I can redefine the entire object on the module export, to keep the reference but not the existing properties.


I can redefine the entire exports object within the require cache, which allows the properties themselves to be redefined.

const cachePath = require.resolve('next/dist/build/output/log')
const cacheObject = require.cache[cachePath]
cacheObject.exports = { ...cacheObject.exports }

@atkinchris
Copy link
Collaborator

Please can you try the new beta version, to see if this works for you?

npm i next-logger@4.0.0-beta.1

@atkinchris
Copy link
Collaborator

Version 4.0.0 has been published, bringing Next 14 support!

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