Morgan Logger + Express.js: writing file AND showing in console

前端 未结 2 1363
面向向阳花
面向向阳花 2021-02-05 11:26

I\'m trying to use Morgan with Express.js to write a log file while showing my logs on the console as well. I\'m using this code:

var logger = require(\'morgan\'         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 12:24

    From github

    var logger = require('morgan');
    
    app.use(logger('common', {
        stream: fs.createWriteStream('./access.log', {flags: 'a'})
    }));
    app.use(logger('dev'));
    

提交回复
热议问题