[英]Why winston is not logging http request
我正在尝试使用Winston库来记录请求并将其保存到文件中。
logger.debug(req.body);
它保存[object Object]而不是请求正文。 有人知道我在做什么错吗?
尝试这样做
logger.debug(req.body.toSource());
toSource()方法表示对象的源代码。
您可以将morgan与winston结合使用以自动记录所有请求
var logger = new winston.Logger({
transports: [
new winston.transports.File({
level: 'info',
filename: './logs/all-logs.log',
handleExceptions: true,
json: true,
maxsize: 5242880, //5MB
maxFiles: 5,
colorize: false
})
],
exitOnError: false
}),
logger.stream = {
write: function(message, encoding){
logger.info(message);
}
};
app.use(require("morgan")("combined", { "stream": logger.stream }));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.