logtemplate

package
v3.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

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 Func

type Func[C, D any] func(output Buffer, ctx C, data *D, extraParam string) (int, error)

Func renders one dynamic template tag.

type Template

type Template[C, D any] struct {
	// contains filtered or unexported fields
}

Template is a precompiled log template.

func Build

func Build[C, D any](format string, tagFunctions map[string]Func[C, D]) (*Template[C, D], error)

Build parses format once and returns a reusable template.

func (*Template[C, D]) Chains

func (t *Template[C, D]) Chains() ([][]byte, []Func[C, D])

Chains returns the fixed template parts and functions used by Execute.

func (*Template[C, D]) Execute

func (t *Template[C, D]) Execute(output Buffer, ctx C, data *D) error

Execute renders the template into output.

type UnknownTagError

type UnknownTagError struct {
	Tag   string
	Param string
	Hint  string
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL