How to disable HTTP request logs in Node/Express.js

后端 未结 3 1181
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 15:55

I\'m currently working on an application based on Node/Express.js.

I have a lot of different resources files (images, css, js...) that I don\'t want to be logged when ex

相关标签:
3条回答
  • 2021-02-01 16:45

    On express.js 4,

    comment: //app.use(morgan('dev'));

    0 讨论(0)
  • 2021-02-01 16:48

    maybe this helps

    app.use((req, res, next) => {
      if (
        [
          ".css",
          ".js",
          ".jpg",
          ".jpeg",
          ".gif",
          ".ico",
          ".png",
          ".bmp",
          ".pict",
          ".csv",
          ".doc",
          ".pdf",
          ".pls",
          ".ppt",
          ".tif",
          ".tiff",
          ".eps",
          ".ejs",
          ".swf",
          ".midi",
          ".mid",
          ".ttf",
          ".eot",
          ".woff",
          ".woff2",
          ".otf",
          ".svg",
          ".svgz",
          ".webp",
          ".docx",
          ".xlsx",
          ".xls",
          ".pptx",
          ".ps",
          ".class",
          ".jar"
        ].indexOf(path.extname(req.path)) == -1
      ) {
        logger("dev")(req, res, next);
      } else {
        next();
      }
    });
    
    0 讨论(0)
  • 2021-02-01 16:58

    Move the logging pluggin below the resource pluggin in the app initialization. Done.

    Woohoo for Connect!

    0 讨论(0)
提交回复
热议问题