Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 300
Dail Avatar asked Jul 27 '26 10:07

Dail


1 Answers

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);
like image 67
Peter Lyons Avatar answered Jul 29 '26 19:07

Peter Lyons