fix: honor per-target level filter on single-element targets array#2432
Open
fix: honor per-target level filter on single-element targets array#2432
targets array#2432Conversation
The single-target shortcut in `lib/worker.js` returned the raw stream
directly, bypassing `pino.multistream` and silently dropping the
`targets[i].level` filter. As a result, `pino.transport({ targets:
[{ level: 'error', ... }] })` emitted info/warn/debug logs even
though the user explicitly requested error-only filtering.
Skip the shortcut when a `level` is set on the single target/pipeline
and route through the multistream path that already enforces per-target
filtering. Update `usesMultistream` in `lib/transport.js` so
`transportUsesMultistreamSym` is set whenever per-target filtering will
run, keeping the existing `formatters.level` warning consistent.
Behavior is unchanged when no `level` is set on the single target.
Closes #1996
Member
|
CI is failing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
levelfilter not work for transports #1996 — the per-targetlevelfilter was silently ignored whenpino.transport({ targets: [...] })contained a single element.lib/worker.jsreturned the raw stream directly, bypassingpino.multistream(which is the only place that consultstargets[i].level).levelis set on the single target/pipeline, we fall through to the multistream path that already enforces per-target filtering. Whenlevelis not set, behavior is unchanged.Root cause
lib/worker.js:126:The level captured at line 85 (
level: t.level) was collected and then discarded for the one-element case. Sotargets: [{ level: 'error', target: '...' }]emitted info/warn/debug logs anyway — the exact symptom reported in #1996.Fix
lib/worker.js:lib/transport.js— extendusesMultistreamsotransportUsesMultistreamSymis set whenever per-target filtering will run in the worker. This keeps the existingformatters.levelwarning (pino.js:169) consistent: if filtering happens, the numericlevelinvariant must hold.Scope
Intentionally minimal — fixes the case where
levelis set (the #1996 reproducer) without altering the no-level case. The remaining asymmetry (single target with no level inheritslogger.levelinstead of defaulting toinfolike multistream does) is a separate semver-major decision and is left for a follow-up.Test plan
levelfilter not work for transports #1996 verbatim (targets: [{ level: 'error', ... }]→ only error reaches destination)logger.levelgating)test/transport/core.test.js(38 tests) — all passtest/transport/{pipeline,targets,sync-true,sync-false,crash,uses-pino-config}.test.js— all passtest/transport-stream.test.js,test/multistream.test.js— all passtest/levels.test.js,test/is-level-enabled.test.js— all passnpm run lint— cleanCloses #1996