3

I'm using Express.JS in node, and i saw that in the log file generate by the logger. I would like to avoid the logging of the image, how could I set the type of requests I want to save in the log file?

Thanks!

Dail
  • 4,622
  • 16
  • 74
  • 109

1 Answers1

10

This should do the trick

var express = require("express");
var logger = express.logger();
var app = express.createServer();

var conditionalLogger = function (req, res, next) {
  if (!(/\.(png|jpg|gif|jpeg)$/i).test(req.path)) {
    logger(req, res, next);
  } else {
    next();
  }
}

app.use(conditionalLogger);
app.use(express.static("./public"));
app.listen(3456);
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274