morgan如何手动写入日志
发布于 7 年前 作者 18823752727 3734 次浏览 来自 问答

express morgan只能自动生成日志,如果我想手动写入日志,该怎么做,求大神指点

2 回复
var express = require('express')
var fs = require('fs')
var morgan = require('morgan')
var path = require('path')

var app = express()

// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), {flags: 'a'})

// setup the logger
app.use(morgan('combined', {stream: accessLogStream}))

app.get('/', function (req, res) {
  res.send('hello, world!')
})
回到顶部