本文介绍了node.js express-winston errorLogger跳过不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将node.js与express-winston一起用于日志记录,
I'm using node.js with express-winston for logging, like that:
var express = require('express');
var app = express();
var winston = require('winston');
var expressWinston = require('express-winston');
var routes = require('./routes/index');
app.use("/", routes);
app.use(
expressWinston.errorLogger({
transports: [
new winston.transports.DailyRotateFile({
name: 'file',
datePattern: '_dd-MM-yyyy.log',
colorize: true,
json: true,
filename: './logs/errors/error_log',
maxsize: 50 * 1024 * 1024,
maxFiles: 10,
zippedArchive: true
}),
new winston.transports.Console({
json: true,
colorize: true
})
],
skip: function(req, res) {
return true;
}
})
);
请注意,我正在使用跳过功能并返回true(出于测试目的),以便跳过所有错误日志记录,如此处所示:快速Winston选项
Notice that I'm using the skip function and returning true (for test purpose) in order to skip all error logging like written here: express-winston options
但这不起作用,有什么主意吗?
but it doesn't work, any ideas?
推荐答案
根据 README.md :
对于您的示例,您想使用ignoreRoute
选项,在您的情况下,该选项将是一个返回true
的函数.
For your example you want to use the ignoreRoute
option which for your case would be a function that returns true
.
app.use(
expressWinston.errorLogger({
transports: [
new winston.transports.DailyRotateFile({
name: 'file',
datePattern: '_dd-MM-yyyy.log',
colorize: true,
json: true,
filename: './logs/errors/error_log',
maxsize: 50 * 1024 * 1024,
maxFiles: 10,
zippedArchive: true
}),
new winston.transports.Console({
json: true,
colorize: true
})
],
v------------------------------ use `ignoreRoute` instead of `skip`
ignoreRoute: function(req, res) {
return true;
}
})
);
这篇关于node.js express-winston errorLogger跳过不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!