structured

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package structured provides a Transport that always outputs a single JSON object per log entry with msg, level, and time fields by default.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	transport.BaseConfig

	// MessageField is the key for the joined message text. Defaults to "msg".
	MessageField string

	// DateField is the key for the timestamp. Defaults to "time".
	DateField string

	// LevelField is the key for the log level. Defaults to "level".
	LevelField string

	// DateFn overrides the default ISO-8601 timestamp.
	DateFn func() string

	// LevelFn overrides the default level string.
	LevelFn func(loglayer.LogLevel) string

	// MessageFn formats the message portion. Its return value is used as the message text.
	MessageFn func(params loglayer.TransportParams) string

	// Writer overrides the default output (os.Stdout).
	Writer io.Writer
}

Config holds configuration options for Transport.

type Transport

type Transport struct {
	transport.BaseTransport
	// contains filtered or unexported fields
}

Transport always outputs one JSON object per log entry. All messages are joined with a space and placed under MessageField.

func New

func New(cfg Config) *Transport

New creates a Transport from the given Config.

func (*Transport) GetLoggerInstance

func (s *Transport) GetLoggerInstance() any

GetLoggerInstance returns nil; structured transport has no underlying logger library.

func (*Transport) SendToLogger

func (s *Transport) SendToLogger(params loglayer.TransportParams)

SendToLogger writes one JSON object per entry: the configured level, date, and message fields first (in that order), followed by Data and Metadata entries in iteration order. Per-value marshaling uses goccy/go-json so structs, slices, and json.Marshaler types render exactly as encoding/json would.

Directories

Path Synopsis
module

Jump to

Keyboard shortcuts

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