Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multistream dedupe example in documentation does not work #1506

Closed
celebro opened this issue Jul 25, 2022 · 5 comments
Closed

Multistream dedupe example in documentation does not work #1506

celebro opened this issue Jul 25, 2022 · 5 comments

Comments

@celebro
Copy link

celebro commented Jul 25, 2022

The following example from documentation about dedupe flag in multistream (https://github.com/pinojs/pino/blob/master/docs/api.md#pino-multistream) does not work as intended, it only logs info and error, while debug and fatal are ignored.

var pino = require('pino')
var multistream = pino.multistream
var streams = [
  {stream: process.stdout},
  {level: 'error', stream: process.stderr},
]

var opts = {
    levels: {
        silent: Infinity,
        fatal: 60,
        error: 50,
        warn: 50,
        info: 30,
        debug: 20,
        trace: 10
    },
    dedupe: true,
}

var log = pino({
  level: 'debug' // this MUST be set at the lowest level of the
                // destinations
}, multistream(streams, opts))

log.debug('this will be written ONLY to process.stdout')
log.info('this will be written ONLY to process.stdout')
log.error('this will be written ONLY to process.stderr')
log.fatal('this will be written ONLY to process.stderr')
@mcollina
Copy link
Member

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

@celebro
Copy link
Author

celebro commented Jul 25, 2022

I'm afraid I can't dedicate the time for implementing a fix, I can only add what I'm currently using instead is specifying a stream for every log level:

var streams = [
    { level: 'debug', stream: process.stdout },
    { level: 'info', stream: process.stdout },
    { level: 'warn', stream: process.stdout },
    { level: 'error', stream: process.stderr },
    { level: 'fatal', stream: process.stderr }
];

bl00dhound added a commit to bl00dhound/pino that referenced this issue Aug 3, 2022
@bl00dhound
Copy link
Contributor

Hi, there!
There are two parts of problem:

  • ifdedup is set totrue log is sent to the stream with the same level only. That's the reason why we can't find log with fatal level in process.stderr stream. I've fixed it in my PR.
  • if level of stream isn't set initially, info level will be set by default. So, debug logs can't put to the stream with info level. That's more complicated problem than the previous one because we need to synchronize two entities (pino-logger and multistream). pino-logger has access to streams array but multistream entity knows nothing about default level in pino-logger. Probably, as a solution, I could add a couple of lines in the documentation about independent default log level in streams. Does it make sense?

@mcollina
Copy link
Member

mcollina commented Aug 4, 2022

should be fixed in latest master

@mcollina mcollina closed this as completed Aug 4, 2022
@github-actions
Copy link

github-actions bot commented Sep 4, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants