【发布时间】:2019-10-28 17:22:44
【问题描述】:
我正在尝试通过express-winston 的msg: 对象记录{{ req.body }}。
我已经使用 expressWinston.requestWhitelist.push('body'); 将正文列入白名单,但它仍未出现在日志中。
export const accessLogger = (router: Router) => {
expressWinston.requestWhitelist.push('body');
router.use(expressWinston.logger({
level: "info";
format: winston.format.simple(),
transports: [
new winston.transports.Console()
],
meta: false,
metaField: null!,
msg: "HTTP {{ req.method }} {{ req.url }} {{ req.body }}",
expressFormat: true
}));
}
使用:
curl -X POST -H "Accept: application/json" -d '{"test": "value"}' http://localhost:someport'
目前在日志中如下所示:
info: POST / 200 1ms
应该看起来像:
info: POST / 200 1ms {\"test\": \"value\"}
如果我使用meta:true 启用meta 我知道并看到它在那里:
info: POST / 200 1ms {"req":{"url":"/","headers":{"host":"localhost:someport","user-agent":"curl/7.63.0","accept":"application/json","content-length":"17","content-type":"application/x-www-form-urlencoded"},"method":"POST","httpVersion":"1.1","originalUrl":"/","query":{},"body":{"{\"test\": \"value\"}":""}},"res":{"statusCode":200},"responseTime":1}
但我现在不想让整个元数据填满我的日志。
【问题讨论】:
标签: javascript node.js typescript express winston