简体   繁体   中英

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

I am trying to apply @elastic/ecs-pino-format to nestjs-pino . Under the good nestjs-pino is using 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) . 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. 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. Also I have noticed issues where @elastic/ecs-pino-format can't handle fastify. Has anyone had similar issues ?

So I was confused with pino and pino-http and how they were integrated in 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 . 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 .

pino-http supports passing

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

for changing the keys of req and res . As for the data that req and res contain, http-pino has another option for transforming them

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

For more information about pino HTTP options .

Hope this helps anyone facing the same problem or want nestjs with Elastic Common Schema (ecs) logs.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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