pinojs / koa-pino-logger

🌲 pino logging koa middleware
MIT License
94 stars 27 forks source link

Remove some headers from request log #29

Closed katlimruiz closed 4 years ago

katlimruiz commented 4 years ago

Hi

So I want to remove some headers from the req log object.

{"level":30,"time":1590769833405,"pid":6,"hostname":"dpy-84f9f44984-zljpx",

"req":{"id":42,"method":"GET","url":"/user/xxx","headers":{"host":"api.staging.com","x-site":"93c4a841f427453a83aa43dbd89c88c8","authorization":"Bearer eyJhbG...Ww","request-id":"|8793d45c-423560962eae0842.5.","x-request-id":"f76c82cd-4d02-42ea-8914-8f88858891f9","x-envoy-expected-rq-timeout-ms":"3000","x-envoy-original-path":"/c/user/xxx","content-length":"0"},"remoteAddress":"::ffff:10.244.2.188","remotePort":51546},

"res":{"statusCode":200,"headers":{"x-request-id":"f76c82cd4d0242ea89148f88858891f9","vary":"Origin","content-type":"application/json; charset=utf-8","content-length":"888"}},

"responseTime":7,"msg":"request completed","v":1}

According to my research I would have to modify the static pino.serializers object, and hook into that. However, since I'm using koa-pino-logger, I don't seem to find a way to do it from the outside.

How can I access to the internal pino object?

katlimruiz commented 4 years ago

I'm guessing this would be how?

https://github.com/pinojs/pino-http

var logger = require('pino-http')({
  // Define custom serializers
  serializers: {
    err: pino.stdSerializers.err,
    req: pino.stdSerializers.req,
    res: pino.stdSerializers.res
  },

But then I would have to import stdserializers to my own project, right? That seems lacking encapsulation.

katlimruiz commented 4 years ago

I created this library

https://github.com/Juntoz/pino-serializer-shorten

so I was able to solve it.