pinojs / pino

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

Print warning on changing log level when using multistream #2030

Open rluvaton opened 4 weeks ago

rluvaton commented 4 weeks ago

I just spent 3h debugging why no logs output when used the elasticsearch transport with ECS format and stdout transport

And because ECS format change the log level, it did not logged as it's forbidden in multistream

So it would be great if we changed the log level and used multiple transports there will be warning reported


Log level shape should not change when using multiple transports if I understand correctly from here

mcollina commented 3 weeks ago

Log level shape should not change when using multiple transports if I understand correctly from here

Yes exactly.


Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

rluvaton commented 3 weeks ago

@Tamir-M you wanted to get into open source, here is an easy issue

I can help you if you want as I'm familiar with the codebase

if you are not interested, you can comment here so other people from the community will know and can take it if they are interested

Tamir-M commented 3 weeks ago

@Tamir-M you wanted to get into open source, here is an easy issue

I can help you if you want as I'm familiar with the codebase

if you are not interested, you can comment here so other people from the community will know and can take it if they are interested

Hi I'm sure @Livour would love to work on this as he's more familiar with the issue.

Livour commented 2 weeks ago

After inspecting the issue I found out that it only occurs when passing a transport stream to the pino function. for example, the following test would currently fail:

test('throws when custom level formatter is used with a multi-targets transport stream', async ({ throws }) => {
  throws(() => {
    pino({
      level: 'info',
      formatters: {
        level (label) {
          return label
        }
      }
    },
    transport({
      targets: [
        {
          target: 'source1'
        },
        {
          target: 'source2'
        }
      ]
    })
    )
  },
  Error('transport.targets do not allow custom level formatters'))
})

I tried fixing it but I found it rather difficult because it only occurs when we pass a pre-made stream to the function (the transport function returns a ThreadStream), any advice?