How to use Morgan logger?

后端 未结 10 1623
囚心锁ツ
囚心锁ツ 2020-12-07 11:19

I cannot log with Morgan. It doesn\'t log info to console. The documentation doesn\'t tell how to use it.

I want to see what a variable is. This is a code from

10条回答
  •  既然无缘
    2020-12-07 11:54

    var express = require('express');
    
    var fs = require('fs');
    
    var morgan = require('morgan')
    
    var app = express();
    
    // create a write stream (in append mode)
    var accessLogStream = fs.createWriteStream(__dirname + '/access.log',{flags: 'a'});
    
    
    // setup the logger
    app.use(morgan('combined', {stream: accessLogStream}))
    
    
    app.get('/', function (req, res) {
      res.send('hello, world!')
    });
    

    example nodejs + express + morgan

提交回复
热议问题