Class LogSafe
X-Forwarded-For entry, a custom resolver's result) on a single line
when it is written into plain-text log output or the MDC.
Without this, a value containing a line break could forge an extra,
genuine-looking log line (log injection). Control characters are replaced
by visible escapes (a backslash followed by n, r, t,
or u and four hex digits), in the same style
JsonInvocationEventEmitter
uses, rather than removed, so an injection attempt stays visible in the
log. Escaped are C0 controls and DEL, C1 controls (including NEL,
U+0085) and the Unicode line and paragraph separators
(U+2028, U+2029), which some log viewers also treat as
line breaks. Everything else, including non-ASCII letters, is kept as is.
The common case costs a single scan: a value with nothing to escape is returned as the same instance, without copying.
This class is used internally by this library's emitters and MDC propagation. It is public only because those live in different packages; it is not part of the supported API and may change without notice.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringsingleLine(String value) Returnsvaluewith every line-breaking or invisible control character replaced by a visible escape.
-
Method Details
-
singleLine
Returnsvaluewith every line-breaking or invisible control character replaced by a visible escape.- Parameters:
value- the value to make safe, may benull- Returns:
valueitself when nothing needs escaping, an escaped copy otherwise, ornullfornull
-