sainsburys-tech / next-logger

JSON logging patcher for Next.js
MIT License
144 stars 14 forks source link

Is there any way to get application specific context injected into the logger mixin? #27

Closed pixelpax closed 3 months ago

pixelpax commented 5 months ago

Been smashing my head against this for a minute, but I don't understand how preloaded modules work well enough.

I'm trying to add in user-specific data to pino.

Something like:

  pino({
    mixin: () => ({
      foo: global.sharedData?.foo || "foo",

Except it seems that global is not actually shared between files executed in the next server runtime (e.g. middleware.ts) and the global found in next-logger.config.js

If it was, I could use AsyncLocalStorage, but as it is I don't actually see any way of sharing memory between them. Help!

atkinchris commented 5 months ago

Can you give a bit more context on what you're trying to do, please? Is this something you can add to your log method invocations instead, rather than implicitly mixed in?

atkinchris commented 3 months ago

I'm closing this as stale, but feel free to reopen it with more context.