node 日志

时间:2024-01-11 21:58:32

我们主动控制的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'));//这个是请求日志的打印

node 日志

app.use(logger({stream: accessLog}));//进程日志

node 日志

app.use(function (err, req, res, next) {
var meta = '[' + new Date() + '] ' + req.url + '\n';
errorLog.write(meta + err.stack + '\n');
next();
});

node 日志