log_options

package
v1.25.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package log_options is what an endpoint's audit lines say about the person they concern, and what the service mounting the endpoint adds to them. It is the one place the endpoints take both from, so that a service configures every endpoint it mounts alike.

Index

Constants

View Source
const (
	CategoryAuthentication = "authentication"
	CategoryIam            = "iam"

	TypeStart    = "start"
	TypeEnd      = "end"
	TypeCreation = "creation"

	OutcomeSuccess = "success"
	OutcomeFailure = "failure"
	OutcomeUnknown = "unknown"
)

The ECS vocabulary the endpoints' events are given in: event.category, event.type and event.outcome take values from fixed lists, which these name. An authentication is a start (or, a revocation, an end) whatever became of it, the outcome saying which -- so that one query over the type and the outcome finds every refusal, by whichever route it came.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// EmailAddressHasher names a person's address by its keyed hash, which matches across entries
	// and can be looked up by hashing an address someone gives. With none, no hash is written.
	EmailAddressHasher *pii_hasher.Hasher

	// LogEmailAddress writes the address itself beside the id and the hash. Off by default: the id
	// names an account to whoever can look it up, and the hash an address to whoever has it.
	LogEmailAddress bool

	// EventAttrs are added inside the event group of every audit line, after the endpoint's own
	// fields: a service's dataset, for one, which its log router tells the audit trail by. They are
	// given to the endpoint rather than passed as an event group of LogAttrs because whether two
	// groups of one name are merged is the handler's to decide: utils_go's context logger merges
	// them, slog's own JSON handler writes the key twice, and the library cannot know which a
	// service logs through.
	EventAttrs []slog.Attr

	// LogAttrs are added at the top level of every audit line.
	LogAttrs []slog.Attr
}

func New

func New(options ...Option) *Config

func (*Config) Apply

func (c *Config) Apply(options ...Option)

Apply sets options on a config that exists already, as on an endpoint's Log once it is made: a service that makes its endpoints in one place and has its hasher in another adds the hasher without replacing what was set before. Unlike New, it keeps what it is not given.

func (*Config) Attrs

func (c *Config) Attrs(attrs ...any) []any

Attrs is the attributes of an audit line with the LogAttrs after them.

func (*Config) EmailAddressHash

func (c *Config) EmailAddressHash(emailAddress string) string

EmailAddressHash is the keyed hash of emailAddress, or empty without a hasher or an address.

func (*Config) Event

func (c *Config) Event(categories []string, types []string, action string, outcome string, reason string) slog.Attr

Event is the event group of an audit line: the ECS categories, types, action and outcome the endpoint gives it, the reason when there is one, and then the EventAttrs.

func (*Config) User

func (c *Config) User(id string, emailAddress string) *schema.User

User names the same person for the request log, which takes its user from the HTTP context.

func (*Config) UserAttrs

func (c *Config) UserAttrs(id string, emailAddress string) []any

UserAttrs names the person an audit line concerns, as the attributes of its user group: the id when there is one, the address's keyed hash with a hasher, and the address itself only when LogEmailAddress is set.

type Option

type Option func(*Config)

func WithEmailAddressHasher

func WithEmailAddressHasher(emailAddressHasher *pii_hasher.Hasher) Option

func WithEventAttrs

func WithEventAttrs(eventAttrs ...slog.Attr) Option

WithEventAttrs adds to the event group of every audit line. They should not repeat the endpoint's own fields -- category, type, action, outcome and reason: a handler that merges groups lets the later value replace the endpoint's, and one that does not writes the key twice.

func WithLogAttrs

func WithLogAttrs(logAttrs ...slog.Attr) Option

func WithLogEmailAddress

func WithLogEmailAddress(logEmailAddress bool) Option

Directories

Path Synopsis
Package log_options_testing captures the lines an endpoint logs, through the logger the services log through, for the endpoints' tests of what their audit lines say.
Package log_options_testing captures the lines an endpoint logs, through the logger the services log through, for the endpoints' tests of what their audit lines say.

Jump to

Keyboard shortcuts

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