fix(logs): respect log level explicitly declared by structured loggers#4624
Open
fcsouza wants to merge 1 commit into
Open
fix(logs): respect log level explicitly declared by structured loggers#4624fcsouza wants to merge 1 commit into
fcsouza wants to merge 1 commit into
Conversation
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.
What
The Docker log viewer classifies log lines purely by keyword matching and ignores the log level the application actually declared. Structured log lines (pino, bunyan, winston, zap, slog, logfmt) end up with wrong badges:
{"level":"error",...}never matches the error patterns (they expect whitespace-delimited words likeerror:), so a pino error line falls through to the debug branch via\b(?:version|...|get|post)\b— pino lines always carry"version"/"method":"GET".{"level":"warn","msg":"Webhook status event..."}is classified as info because\bstatus\bmatches first.{"level":"info","msg":"Request completed"}is classified as success because of\bcompleted\b.Fix
Check for an explicitly declared level before any inference, and only fall back to the existing keyword heuristics when none is present:
"level":"error","severity":"ERROR"(GCP),"log.level"(ECS)"level":50(pino/bunyan 10–60 scale, syslog/GELF 0–7 scale)level=errorA declared level also wins over the inferred
statusCodeclassification. Unknown level names fall back to the keyword detection, which is unchanged.Kept intentionally minimal (no scoring system) per the maintainer feedback on #3070.
Issues related
Closes #4589. Related: #4538, #1996.
Before / After
Same container (pino JSON + logfmt lines), tested on a local dev instance (
pnpm dokploy:dev):Before —
"level":"error"shows asdebug,"level":"warn"asinfo,"level":"info"assuccess:After — badges match the declared level; numeric pino levels and logfmt are also respected:
Tests
Added
__test__/utils/log-type.test.ts— 12 tests covering pino/winston/zap string levels, pino/bunyan numeric levels, syslog/GELF numeric levels, GCP severity, ECS log.level, logfmt, precedence over statusCode and keywords, fallback for unknown level names, and the regression cases from #4589/#4538. Full vitest suite,tsc --noEmitand Biome pass.Checklist
canarybranch.