pinojs / pino-http

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

Too verbose for development? #60

Open broom9 opened 5 years ago

broom9 commented 5 years ago

The multiple-line logs in console feel a bit verbose during development. Is there an easy (less custom code) way to output a simple one-line log for each request similar as Morgan?

I realized pino-toke is built for that. But it is also meant to be a CLI tool. We already need to pipe the output to pino-pretty. How do you suggest to use pino-pretty and pino-toke together?

mcollina commented 5 years ago

I don't understand. Why you would need pin-pretty if you are using pino-toke?

broom9 commented 5 years ago

Thanks for the quick reply. I was probably not clear.

In a typical Express-based web app, we could have http logs from express-pino-logger and app logs from calling logger.debug/info/warn/error method from pino.

During development, we would like to pretty print http logs so that each req only generates one line of log (which looks like need to be done by pino-toke), and also pretty print app logs via pino-pretty.

mcollina commented 5 years ago

That use case is not currently supported :/.

davidmarkclements commented 5 years ago

on a side note you might want to checkout http://npm.im/pino-colada

muuhoffman commented 3 years ago

One solution I can think of is to use a custom serializer for development. You would just check your environment for whether you're in development or not and then change the serializer to only include minimal info. Check out the pino-http README to see the documentation for custom serializers.

const expressLogger = expressPino({
  logger,
  serializers: {
    req: (req) => {
      if (process.env.NODE_ENV === "development") {
        return {
          method: req.method,
          url: req.url,
        };
      } else {
        return req;
      }
    },
  },
});