severity(): Notice band is unreachable — sevNotice(5) is dead code #2

Open
opened 2026-08-10 09:06:14 +02:00 by heiko · 0 comments
Owner

Summary

severity() in syslog.go maps slog.Level to RFC 5424 severities,
but no input ever produces sevNotice(5). The INFO band maps to
info(6) and the WARN band to warning(4); Notice is skipped
entirely. sevNotice is a defined constant with no code path.

Where

syslog.go, func severity(l slog.Level) int:

case l < slog.LevelWarn:  // INFO band  -> info(6)
case l < slog.LevelError: // WARN band  -> warning(4)

Nothing returns sevNotice.

Impact

An application that defines the conventional Notice level between
Info(0) and Warn(4) — i.e. slog.LevelInfo + 2 — has its records
framed as info(6) in the journal/syslog formats, losing the
Notice distinction. There is currently no way to emit a
Notice-severity line even though RFC 5424 (and hslog's own constant)
defines one. The mapping is asymmetric: levels above Error already
map upward to crit/alert/emerg, but the low side has a hole at Notice.

Proposal

  1. Adopt a Notice convention and map it: for
    slog.LevelInfo < l < slog.LevelWarn, return sevNotice(5); keep
    exact slog.LevelInfo -> info(6).
  2. Optionally export hslog.LevelNotice = slog.LevelInfo + 2 so
    callers don't hardcode the offset, mirroring how levels above
    Error are already documented.
  3. Consider the text/plain handler's level label too — a Notice
    record currently prints as INFO+2 rather than NOTICE.

Context

Surfaced while wiring log levels into the dcbop container-hardening
tooling (stc-dc-workflow): we want the syslog order
error/warning/notice/info/debug, and hit the Notice gap.

### Summary `severity()` in `syslog.go` maps `slog.Level` to RFC 5424 severities, but no input ever produces `sevNotice(5)`. The INFO band maps to `info(6)` and the WARN band to `warning(4)`; Notice is skipped entirely. `sevNotice` is a defined constant with no code path. ### Where `syslog.go`, `func severity(l slog.Level) int`: case l < slog.LevelWarn: // INFO band -> info(6) case l < slog.LevelError: // WARN band -> warning(4) Nothing returns `sevNotice`. ### Impact An application that defines the conventional Notice level between Info(0) and Warn(4) — i.e. `slog.LevelInfo + 2` — has its records framed as `info(6)` in the `journal`/`syslog` formats, losing the Notice distinction. There is currently no way to emit a Notice-severity line even though RFC 5424 (and hslog's own constant) defines one. The mapping is asymmetric: levels *above* Error already map upward to crit/alert/emerg, but the low side has a hole at Notice. ### Proposal 1. Adopt a Notice convention and map it: for `slog.LevelInfo < l < slog.LevelWarn`, return `sevNotice(5)`; keep exact `slog.LevelInfo` -> `info(6)`. 2. Optionally export `hslog.LevelNotice = slog.LevelInfo + 2` so callers don't hardcode the offset, mirroring how levels above Error are already documented. 3. Consider the text/plain handler's level label too — a Notice record currently prints as `INFO+2` rather than `NOTICE`. ### Context Surfaced while wiring log levels into the dcbop container-hardening tooling (stc-dc-workflow): we want the syslog order error/warning/notice/info/debug, and hit the Notice gap.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
heiko/hslog#2
No description provided.