gpt4 book ai didi

express - 如何修改 Pino express 日志上的日志字段

转载 作者:行者123 更新时间:2023-12-05 08:07:12 26 4
gpt4 key购买 nike

我正在使用 express-pino-logger 作为日志系统。一切正常,但它正在记录大量不需要的数据所有请求数据。那么我如何在记录时限制特定的字段。

var expressPino = require('express-pino-logger')({ prettyPrint: { colorize: true } });
app.use(pino);
app.get('/test',function(req, res) {
req.log.info("Something");
});

上面的代码记录了很多不需要的结果,如下面的 Json。

{"level":30,"time":1559044530446,"pid":2462,"hostname":"PATRALTOP-46","prettyPrint":{"colorize":true},"req":{"id":10,"method":"GET","url":"/user/profile","headers":{"host":"localhost:3011","connection":"keep-alive","user-agent":"Mozilla36","accept":"*/*","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,ta;q=0.8","cookie":"menubShQ","if-none-match":"W2b7bpE08jO8lVNTEV/tg9OIRMd3fI"},"remoteAddress":"::1","remotePort":58260},"res":{"statusCode":304,"headers":{"x-powered-by":"Express","etag":"W2b7b-OpE08jO8lVNTEV/tg9OIRMd3fI"}},"responseTime":106,"msg":"something","v":1}

那么我们如何在记录时指定或删除字段。

最佳答案

在传递给 Pino 实例的选项中设置 base: undefined。它将从每个日志中删除 pidhostname

有更多选项可用于操作日志。有关详细信息,请查看 API 规范: https://github.com/pinojs/pino/blob/HEAD/docs/api.md#base-object

关于express - 如何修改 Pino express 日志上的日志字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56344104/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com