Expand description
Formatting helpers for log fields.
Operator-facing fields print the value, never Rust’s Option spelling: a line
reads alpn=h3, not alpn=Some("h3"). When the value is absent the field
still appears, carrying ABSENT — dropping it instead would make the shape
of the line depend on its contents, which is exactly what a grep or a log
shipper cannot cope with.
The rule is about audience, not about level: info/warn lines are read by
whoever is running the server, so they print values. The debug forensic dump
in crate::conn deliberately keeps Debug shapes — there the Rust spelling
of a header map, or of an absent :protocol, is the evidence D3 is waiting
for.
The third rule is about provenance: or_dash prints with Display, which
escapes nothing, so it is only for values the server produced or validated
itself — the ALPN it negotiated from its own list, the SNI rustls accepted as
a DNS name, a SocketAddr it resolved. Bytes the peer chose (the user-id of
a rejected credential) are recorded as a plain str field instead, which
tracing prints quoted and Debug-escaped: username="user1", and a newline
or a terminal escape sequence inside it stays on the one line, spelled out.
systemd splits a service’s stdout on \n, so an unescaped newline would
otherwise hand an unauthenticated client a journal entry of its own.
The fourth rule is about size: several of those peer-chosen values are a
whole field section’s worth of bytes, so bounded caps what any one of
them can write into the journal. Length and provenance are separate
concerns, and both apply to the same fields – bounded does not escape
anything, and recording its result with % would undo the third rule.
Some peer bytes have no field of their own to be recorded in: they arrive
already inside somebody else’s Display, and the log sees only the sentence
they ended up in – a QUIC close reason phrase inside the error the closing
line reports, say. The sigil cannot save those, because by the time the sigil
is chosen the peer’s bytes are already part of a value that formats itself.
escaped_bytes is the answer for them: applied where the peer’s bytes
enter the value rather than where the value is logged, it applies both rules
at once and hands back something the rest of the program may print with
Display from then on. peer_error is that answer applied to the value
this server meets it in – a QUIC connection error – so that the two places
one of those reaches a log line apply the rule by calling the same name.
Structs§
- Sampler
- How often a warning a peer can repeat at will is allowed to be loud.
Constants§
- ABSENT
- What an absent value prints as.
Functions§
- addresses
- Renders a resolved address list at a length a log line can afford.
- bounded
- Caps a peer-chosen token at what a log line can afford to carry.
- bounded_
bytes boundedfor bytes that are not known to be UTF-8.- escaped_
bytes bounded_byteswith the escaping applied too, for peer bytes that will be printed withDisplay.- or_dash
- Formats an optional log field: the value itself, or
ABSENT. - peer_
error - The same error, with any reason phrase the peer wrote passed through
escaped_bytes.