Dail
Dail

Reputation: 4608

Avoiding image logging in Express.js

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!

Upvotes: 3

Views: 1932

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146104

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);

Upvotes: 10

Related Questions