简体   繁体   English

NestJS 中的 HTTP Pino 记录器和 Elastic Common Schema (ecs) 格式

[英]HTTP Pino logger and Elastic Common Schema (ecs) format in NestJS

I am trying to apply @elastic/ecs-pino-format to nestjs-pino .我正在尝试将@elastic/ecs-pino-format应用于nestjs-pino Under the good nestjs-pino is using http-pino .根据好 nestjs-pino 是使用http-pino I have noticed that http-pino adds the request object inside [Symbol(pino.chindings)] and I am assuming it's using a child logger.So I tried to write a custom formatter for extracting the req by calling obj.res.log.bindings() and putting at http.request to be compliant with Elastic Common Schema (ecs) .我注意到http-pino[Symbol(pino.chindings)]添加了请求对象,我假设它正在使用子记录器。所以我尝试编写一个自定义格式化程序来通过调用obj.res.log.bindings()来提取obj.res.log.bindings()并放入http.request以符合Elastic Common Schema (ecs) The problem I face is now my log contains duplicate the req and the http.request and can't find a way to remove it.我现在面临的问题是我的日志包含重复的reqhttp.request并且找不到删除它的方法。 Not sure if I am looking in the wrong direction but I have found a lot of issues trying to make nestjs-pino print Elastic Common Schema (ecs) format logs.不确定我是否在寻找错误的方向,但我发现尝试使nestjs-pino打印Elastic Common Schema (ecs)格式日志时遇到很多问题。 Also I have noticed issues where @elastic/ecs-pino-format can't handle fastify.我还注意到@elastic/ecs-pino-format无法处理 fastify 的问题。 Has anyone had similar issues ?有没有人有类似的问题?

So I was confused with pino and pino-http and how they were integrated in nesjs-pino .所以我对pinopino-http以及它们如何集成到nesjs-pino感到困惑。 From the looks of it @elastic/ecs-pino-format doesn't handle all the specifics for Elastic Common Schema (ecs) in pino-http .从它的外观来看, @elastic/ecs-pino-format并没有处理pino-http Elastic Common Schema (ecs) 的所有细节。 So what I ended up doing was passing in nestjs-pino as a configuration a merge of the format object from @elastic/ecs-pino-format and configuring pino-http .所以我最终做的是将nestjs-pino作为配置传递,合并来自@elastic/ecs-pino-format的格式对象并配置pino-http

pino-http supports passing pino-http支持传递

customAttributeKeys: {
req: 'http.request',
res: 'http.response',
}

for changing the keys of req and res .用于更改reqres的键。 As for the data that req and res contain, http-pino has another option for transforming them对于reqres包含的数据, http-pino有另外一种转换方式

serializers: {
req: (log) => {... return transform },
res: (log) => {... return transform },
} 

For more information about pino HTTP options .有关pino HTTP 选项的更多信息。

Hope this helps anyone facing the same problem or want nestjs with Elastic Common Schema (ecs) logs.希望这可以帮助任何面临相同问题或想要使用Elastic Common Schema (ecs)日志的 Nestjs 的人。

同样在这里...有任何更新吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM