logging到所有请求

我有一个日志logging的问题,但我没有线索如何阻止它,我只是希望它login的视图文件,而不是静态文件..

这是我的代码:

//logger. app.use(function(request, response, next) { if(app.get('env') == 'development') { console.log('%s %s', request.method, request.url); console.log('connection from: ' + request.ip); } var file = request.url.slice(1 + request.url.indexOf('/')); app.get(request.url, function(request, response) { response.render(file, { //Var to be named in the render : value; 'Title': Title, 'result': result }); }); next(); }); //Set directory for static files (css, js, img) app.use(express.static(__dirname + '/public')); 

当我进入控制台查看结果。 我明白了

 GET /css/bootstrap.css connection from: 127.0.0.1 GET /css/cover.css connection from: 127.0.0.1 GET /index connection from: 127.0.0.1 GET /css/cover.css connection from: 127.0.0.1 GET /css/bootstrap.css connection from: 127.0.0.1 

我只是希望它loggingGET /index而不是其余。

如果你使用的是express.js,只需使用诸如“morgan”之类的日志logging中间件,让express为你处理日志。 例如下面的代码会自动打印一些日志:

 var express = require('express'); var morgan = require('morgan'); // Logging middleware var app = express(); app.use(morgan('dev')); // 'dev', 'short', 'tiny'. or no argument (default) app.get('/', function(req, res){ res.send('hello world'); }); app.listen(3000); 

当你打localhost:3000时,你会看到日志logging(也是颜色):

GET / 200 3ms – 11b