bithavoc / express-winston

express.js middleware for winstonjs
https://www.npmjs.com/package/express-winston
MIT License
797 stars 187 forks source link

Routes Whitelist for logging as opposed to ignoredRoutes #108

Closed oddoye-david closed 8 years ago

oddoye-david commented 8 years ago

Very stressful listing about 20 routes not to get logged, also routes like '/api/items?q=this' don't get picked up in the blacklist.

rosston commented 8 years ago

I do understand the use case, but I think the request, response, and body whitelists cover most sensitive data that you don't want logged. I would think the route itself getting logged isn't really sensitive. Although maybe I'm just not thinking of good examples.

Anyway, you can make your own route whitelist using ignoreRoute or skip. Something like this is what you'd want (no guarantees about its quality, this is just some rough code):

var routeWhitelist = ['/foo', '/bar'];

app.use(expressWinston.logger({
  transports: [new winston.transports.Console()],
  ignoreRoute: function (req, res) {
    return routeWhitelist.indexOf(req.originalUrl || req.url) === -1;
  }
}));
rosston commented 8 years ago

Closed due to inactivity.

gtpan77 commented 3 years ago

use req.path if you want to ignore query params

const routeWhitelist = ['/foo', '/bar'];

app.use(expressWinston.logger({
  transports: [new winston.transports.Console()],
  ignoreRoute: function (req, res) {
    return routeWhitelist.indexOf(req.path) === -1;
  }
}));