pinojs/pino

Question: Is dynamic log redaction possible?

Closed this issue · 3 comments

I would like to censor dynamically so that partial information from the key is still left- for example the first couple chars of an email.

I noticed I can use a function as the value of censor

redact: {
  paths: ['email'],
  censor: helloWorld(),
  }

where helloWorld returns "hello world". But, I'm stuck on figuring out how I can pass the value of the path to the censor func. Alternatively, I know I could write a function to alter the email in the log.info so that it logs the result of the function as opposed to using the redact feature of the log, but that doesn't scale very well. Any insights? I imagine there is a use case where folks would like to leave partial information in the censored logs.

This is currently not supported.

This seems more like a use case for serializers than redact:

'use strict';

const pino = require('pino');

const log = pino({
  serializers: {
    err: pino.stdSerializers.err,
    email: (email) => {
      if (typeof email === 'string') {
        return `${email.slice(0, 3)}...`;
      } else {
        JSON.stringify(email);
      }
    }
  }
});

log.info({
  email: 'some_user_email@pleasedontlog.follow.grdp',
  someOtherKey: 'just a normal log',
});

output:

$ node dynamic-redaction.js | npx pino-pretty
[11:47:19.625] INFO (767135):
    email: "som..."
    someOtherKey: "just a normal log"

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.