pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

formatters with transport #1139

Closed TinOo512 closed 2 years ago

TinOo512 commented 3 years ago

Hi pino!

It looks like any mutation done in formatters.log isn't working when using along transport (tested with pino-pretty and pino/file).

'use strict';

const pino = require('pino');

const p1 = pino({
  formatters: {
    log (object) {
      object.datav1 = JSON.parse(JSON.stringify(object.data));
      delete object.data;

      return object;
    },
  },
});

const p2 = pino({
  formatters: {
    log (object) {
      object.datav1 = JSON.parse(JSON.stringify(object.data));
      delete object.data;

      return object;
    },
  },
  transport: {
    targets: [
      {
        target: 'pino/file',
        options: { destination: './test.log' },
      },
    ],
  },
});

p1.info({
  event: 'testp1',
  data: {
    hello: 'world',
  },
});

p2.info({
  event: 'testp2',
  data: {
    hello: 'world',
  },
});

p1 output to STDOUT:

{"level":30,"time":1632477228653,"pid":977,"hostname":"TinOo-2.local","event":"testp1","datav1":{"hello":"world"}}

p2 output to test.log:

{"level":30,"time":1632477228654,"pid":977,"hostname":"TinOo-2.local","event":"testp2","data":{"hello":"world"}}

According to https://github.com/pinojs/pino/pull/809 this has been fixed in the v6? I didn't take the time to dive in the codebase but if you could provide some guidance where to start I can open a PR.

Thanks!

mcollina commented 3 years ago

Transports pass through a different code paths than prettifiers, so it's likely than a similar fix is needed.

Would you like to dig into what is going wrong and send a PR?

micalevisk commented 2 years ago

is this fixed?

🎆

mcollina commented 2 years ago

Yes!

github-actions[bot] commented 2 years ago

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.