pino icon indicating copy to clipboard operation
pino copied to clipboard

Pino to Pino transport with filtering?

Open FoxxMD opened this issue 11 months ago • 1 comments

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.

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 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.

FoxxMD avatar Dec 09 '24 19:12 FoxxMD

I think yours is the only solution with the current design.

mcollina avatar Dec 11 '24 16:12 mcollina