我们主动控制的log4js,还有一些日志是继承好的,错误日志了,进程日志了,请求日志了。
1.
var express = require('express');
var logger = require('morgan');
var fs = require('fs');
var accessLog = fs.createWriteStream('access.log', {flags: 'a'});
var errorLog = fs.createWriteStream('error.log', {flags: 'a'});
var app = express();
app.use(logger('dev'));//这个是请求日志的打印
app.use(logger({stream: accessLog}));//进程日志
app.use(function (err, req, res, next) {
var meta = '[' + new Date() + '] ' + req.url + '
';
errorLog.write(meta + err.stack + '
');
next();
});