Help us shape the future of Go! Take the 2026 Go Developer Survey

logger

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package logger configures structured logging and carries loggers through contexts.

Index

Constants

View Source
const (
	EventQuarantine  = "quarantine"
	EventReceived    = "received"
	EventCorrelation = "correlation"
)

Event names for the notable proxy events, used as the event tag value.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext returns the attached logger, or a logger that discards output if none is attached.

func New

func New(config Config, output io.Writer) *slog.Logger

New constructs a logger that writes to output using the supplied configuration.

func WithLogger

func WithLogger(ctx context.Context, log *slog.Logger) context.Context

WithLogger returns a child context carrying log without changing the parent context.

Types

type Config

type Config struct {
	// Level is the minimum severity written to the log.
	Level slog.Level `default:"info" help:"Minimum log level (debug, info, warn, error)."`
	// JSON shapes JSON output like the fronted service's logs. Unset writes text.
	JSON JSONTemplate `` /* 351-byte string literal not displayed */
}

Config contains logging flags that can be embedded in a Kong CLI.

func NewConfig

func NewConfig() Config

NewConfig returns the default logging configuration: info-level text output.

type JSONTemplate added in v0.33.0

type JSONTemplate struct {
	// contains filtered or unexported fields
}

JSONTemplate is the JSON shape of SPECTRE's own log lines, so they match the logs of the service SPECTRE stands in for. The zero value writes text instead.

func ParseJSONTemplate added in v0.33.0

func ParseJSONTemplate(text string) (JSONTemplate, error)

ParseJSONTemplate parses a template, or DEFAULT. Unknown placeholders are rejected so a typo fails at startup rather than producing odd logs.

func (*JSONTemplate) UnmarshalText added in v0.33.0

func (t *JSONTemplate) UnmarshalText(text []byte) error

UnmarshalText parses a template, so Kong validates --log-json as it parses flags.

Jump to

Keyboard shortcuts

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