Documentation
¶
Index ¶
- Variables
- func ExecuteChains[C, D any](output Buffer, ctx C, data *D, fixedParts [][]byte, funcChain []Func[C, D]) error
- func IndexControlByte[S ~string | ~[]byte](s S) int
- func IsControlByte(b byte) bool
- func ScrubControls[S ~string | ~[]byte](s S, idx int) []byte
- func WriteSanitized(output Buffer, p []byte) (int, error)
- func WriteSanitizedString(output Buffer, s string) (int, error)
- type Buffer
- type Func
- type Template
- type UnknownTagError
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownTag = errors.New("logtemplate: unknown tag")
ErrUnknownTag indicates that the template references a tag that has no registered renderer. The format may be a bare ${tag} or a parametric ${tag:param}; in both cases the unmatched name is reported via UnknownTagError so callers can extract it programmatically.
Functions ¶
func ExecuteChains ¶
func ExecuteChains[C, D any](output Buffer, ctx C, data *D, fixedParts [][]byte, funcChain []Func[C, D]) error
ExecuteChains renders precompiled template chains into output.
func IndexControlByte ¶ added in v3.5.0
IndexControlByte returns the index of the first byte IsControlByte matches, or -1 if none is present. It scans eight bytes at a time; inputs of 8+ bytes finish with one overlapping word, shorter ones byte-wise.
func IsControlByte ¶ added in v3.5.0
IsControlByte reports whether b is an ASCII control byte that must not pass through to a log line. Tab is preserved because operators frequently use it for delimiting structured fields. CR, LF, NUL, and the other C0/DEL bytes are replaced — they are the bytes attackers use to forge log lines or corrupt terminal output via ANSI escape sequences.
func ScrubControls ¶ added in v3.5.0
ScrubControls returns a copy of s with every byte IsControlByte matches replaced by a space. idx is the index of the first such byte, so the scan starts there and the clean prefix is copied untouched.
A negative idx — what IndexControlByte returns for clean input — is clamped to 0 rather than panicking, so ScrubControls(s, IndexControlByte(s)) is safe even though the callers here take the clean fast path instead.
func WriteSanitized ¶ added in v3.5.0
WriteSanitized writes p to output with ASCII control bytes replaced by spaces. Tabs are preserved. Clean inputs (the common case) forward directly to output.Write with no allocation; dirty inputs are scrubbed into a copy starting at the first control byte.
Types ¶
type Buffer ¶
type Buffer interface {
Len() int
ReadFrom(r io.Reader) (int64, error)
WriteTo(w io.Writer) (int64, error)
Bytes() []byte
Write(p []byte) (int, error)
WriteByte(c byte) error
WriteString(s string) (int, error)
Set(p []byte)
SetString(s string)
String() string
}
Buffer is the render buffer exposed to template functions. The template renderer only requires Write, WriteByte, and WriteString, but the wider bytebufferpool-compatible surface is kept so existing custom logger tags that use methods such as Len, Bytes, Set, or String continue to compile when switching to the shared template renderer.
type Template ¶
type Template[C, D any] struct { // contains filtered or unexported fields }
Template is a precompiled log template.
type UnknownTagError ¶
UnknownTagError is the typed error returned when a template references an unknown tag. Tag is the offending tag including any parametric suffix (without the surrounding "${" / "}"). Param is the parameter portion when the tag was parametric, or the empty string for bare tags. Hint is an optional human-readable suggestion — currently set when a bare tag was referenced but a parametric base of the same name is registered.
func (*UnknownTagError) Error ¶
func (e *UnknownTagError) Error() string
func (*UnknownTagError) Unwrap ¶
func (*UnknownTagError) Unwrap() error