pinojs / pino-noir

🌲 pino log redaction 🍷
MIT License
66 stars 17 forks source link

Pino-noir logs the whole req object #13

Closed Junkern closed 6 years ago

Junkern commented 6 years ago

We are using restify@4.1.1, restify-pino-logger@2.0.0 and the newest pino-noir. We have following log structure (showing only important properties):

{
  "req": {
    "headers": {
      "x-forwarded-for": "11.11.11.11",
      "authorization": "Basic foobar=="
    }
  },
  "res": {
    "statusCode": 200
  }
}

We want to redact the values in the authorization and x-forwarded-for headers:

const noir = pinoNoir(['req.headers.authorization', 'req.headers.x-forwarded-for'], '[redacted]')

app.use(pinoLogger({
    name: 'logger',
    serializers: noir
}))

This, however creates HUUUGE logs, it basically does a JSON.stringify on the req object (about 500 lines of output per log). What am I missing here? Is it due to the old restify version?

Junkern commented 6 years ago

I updated to the newest restify version now, and the problem persists, it logs the whole request object with all its internal properties

davidmarkclements commented 6 years ago

the api of pino-noir could probably be improved but you need pass in the standard request serializer to the serializers option

var restify = require('restify')
var noir = require('pino-noir')
var app = restify.createServer({name: 'app'})
app.use(require('restify-pino-logger')({
  serializers: noir({
    req: pino.stdSerializers.req,
  }, ['key', 'path.to.key', 'check.*', 'also[*]'])
}))