You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My end goal is to have a pino logger that logs to an additional destination when used within a specific scope within my application.
The intuitive, naive thought would be that I could use logger.child() and pass an additional destination so that only when the child logger is used is the additional destination logged to. I know this is not how child works, however.
My current solution is to build the "top-level" pino instance with an additional PassThrough stream in object mode as a destination, used in conjunction with multistream and other destinations. A "scoped" pino instance with just the destination I need is then created.
I then use stream.on('data', (str) => ...) and in the callback check if the log object contains certain properties at which point I pass the log object and level to the scoped pino instance. My implemention of this is working:
My implementation is working but it feels un-pino-like. Is there any way I could better use actual transports to pass logging between Pino instances? Or is there a better way I could go about achieve this desired result? Any insight into a better way to do this would be helpful, thanks.
The text was updated successfully, but these errors were encountered:
My end goal is to have a pino logger that logs to an additional destination when used within a specific scope within my application.
The intuitive, naive thought would be that I could use
logger.child()
and pass an additional destination so that only when the child logger is used is the additional destination logged to. I know this is not howchild
works, however.I also see that it is not possible to add additional destinations to an existing pino instance.
My current solution is to build the "top-level" pino instance with an additional
PassThrough
stream in object mode as adestination
, used in conjunction withmultistream
and other destinations. A "scoped" pino instance with just the destination I need is then created.I then use
stream.on('data', (str) => ...)
and in the callback check if the log object contains certain properties at which point I pass the log object and level to the scoped pino instance. My implemention of this is working:My implementation is working but it feels un-pino-like. Is there any way I could better use actual transports to pass logging between Pino instances? Or is there a better way I could go about achieve this desired result? Any insight into a better way to do this would be helpful, thanks.
The text was updated successfully, but these errors were encountered: