pinojs / pino-http

🌲 high-speed HTTP logger for Node.js
MIT License
531 stars 117 forks source link

Set on completed/error msg at runtime #267

Closed naseemkullah closed 1 year ago

naseemkullah commented 1 year ago

I've recently discovered and fallen in love with req.log.setBindings() and am consolidating disparate logs during requests into just one rich log upon request completion.

A cherry on top would be to be able to override the on completed/error message depending on the route and response. My current workaround is to set an "eventName" property before request completes. Thoughts?

mcollina commented 1 year ago

That's a great one ;).

naseemkullah commented 1 year ago

Ha! I just realized custom messages by route/res is already possible, e.g.:

    customSuccessMessage: (req, res) => {
      if (req.url === '/foo' && res.statusCode === 200) {
        return 'good foo event.';
      }
      return 'request completed.';
    },

While this is not setting it at runtime, the desired outcome is the same.

Closing since functionality already provided 🚀