events

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package events is a small event logging system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithGroup

func WithGroup(ctx context.Context, g *Group) context.Context

WithGroup returns a Context with the provided Group embedded.

Functions further down the call stack can derive Log interfaces with FromContext.

Types

type Event

type Event struct {
	Message string
	Error   bool
	// contains filtered or unexported fields
}

Event is the event information delivered to a Sink.

type Group

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

Group is a grouping of log events going to a common Sink.

func NewGroup

func NewGroup(ctx context.Context, sink Sink, name string) (*Group, error)

NewGroup creates a new Group "name" writing to Sink "sink".

The passed Context is only used for the duration of the NewGroup call.

func (*Group) Finish

func (g *Group) Finish(ctx context.Context) error

Finish signals to the underlying sink that this group is done and reports any errors accumulated by derived Log objects.

type Log

type Log interface {
	Printf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	// Finish should be called in a defer, right after FromContext.
	Finish()
}

Log is the facade that "user" code should expect.

func FromContext

func FromContext(ctx context.Context, topic string) Log

FromContext returns a Log implementation grouping messages under the provided topic.

The returned implementation may be all no-op methods, so callers should avoid logging "expensive" data.

type Sink

type Sink interface {
	// StartGroup is called when a new group is created. The Context should only
	// be used for the duration of the StartGroup call.
	StartGroup(ctx context.Context, group string) error
	// Topic notifies the Sink that a topic has been started. The same topic may
	// be passed multiple times.
	Topic(string)
	// Event is called once per event, some time between StartGroup and
	// FinishGroup.
	Event(group, topic string, ev Event) error
	// FinishGroup is called when the group is finished. The Context may be
	// canceled when this method is called.
	FinishGroup(ctx context.Context, group string) error
}

Sink is the interface that event sinks must implement.

Jump to

Keyboard shortcuts

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