pinojs / koa-pino-logger

🌲 pino logging koa middleware
MIT License
94 stars 27 forks source link

need to exclude certain url paths #23

Open bigriot opened 5 years ago

bigriot commented 5 years ago

My server receives health check pings from a load balancer via '/ping'.

The health check happens every 30 seconds so meaningless logs will pile up rather quickly, especially if I've got multiple instances running at the same time.

I think hapi-pino has something like this with an ignorePaths option, and was wondering if we could get something similar for koa.

alexdeia commented 4 years ago

Hi @bigriot !

You can try something like this

    app.use(async (ctx, next) => {
      if (ctx.url === '/ping') {
        await next();
      } else {
        await logger()(ctx, next);
      }
    });
abeluck commented 4 years ago

This method is not ideal.

If the ignored route uses a log function ctx.log.info, then it will cause an error.