dnjstrom / pino-dev

A simple prettifier for pino with built-in support for commonly used ecosystem packages.
MIT License
10 stars 1 forks source link

Support nestjs-pino #106

Closed GauBen closed 1 year ago

GauBen commented 2 years ago

Hey there!

Could you please add support for nestjs-pino?

It works nicely out of the box. I use it with -m '{"ns":"context"}' to print the context, but it looks weird on http requests that have no context:

image

Maybe add a default [HTTP] context (in another color) for http requests?


Edit: logs have a property req.id that allows correlating logs to requests, it might be interesting to display it

dnjstrom commented 1 year ago

Hi

Sorry for the delay in getting back to you regarding this issue. Not sure if still relevant but I believe adding HTTP to the ns property by default would be making too many assumptions about how the logger is going to be used. If a different user doesn't use the ns property then they would just get the reverse issue that you're seeing. Instead, in this case I believe setting the ns property of the log object could rather be configured as part of setting up pino-http. You might, for instance, configure pino-http with a child logger defaulting the ns property to HTTP.

const httpLogger = require('pino-http')({
  logger: parentLogger.child({ns: 'HTTP'})
})

Similarly, you might want to consider configuring the rename or duplication of context to ns using something like the formatters config of pino.

I like your idea about displaying the req.id property! Maybe something like the below where 1234 is the request id? 🤔

17:42:59 Info: GET(1234) /ping 200 22ms

I'll close this issue since it was opened a long time ago and might not be relevant anymore, but feel free to open it again if you'd like to continue the discussion 👍