logging

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package logging provides structured logging sinks for BOOTy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KafkaConfig

type KafkaConfig struct {
	Brokers       []string `json:"brokers"`
	Topic         string   `json:"topic"`
	TLS           bool     `json:"tls,omitempty"`
	SASLUser      string   `json:"saslUser,omitempty"`
	SASLPassword  string   `json:"-"`
	SASLMechanism string   `json:"saslMechanism,omitempty"` // "PLAIN", "SCRAM-SHA-256", "SCRAM-SHA-512".
	Compression   string   `json:"compression,omitempty"`   // "snappy", "lz4", "zstd", "none".
}

KafkaConfig holds Kafka connection settings.

func (*KafkaConfig) Validate

func (c *KafkaConfig) Validate() error

Validate checks KafkaConfig for required fields.

type KafkaHandler

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

KafkaHandler implements slog.Handler for structured log output.

func NewKafkaHandler

func NewKafkaHandler(writer MessageWriter, topic string, identity MachineIdentity) *KafkaHandler

NewKafkaHandler creates a structured logging handler.

func (*KafkaHandler) Close

func (h *KafkaHandler) Close() error

Close flushes and closes the underlying writer.

func (*KafkaHandler) Enabled

func (h *KafkaHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*KafkaHandler) Handle

func (h *KafkaHandler) Handle(_ context.Context, r slog.Record) error

Handle processes a log record.

func (*KafkaHandler) WithAttrs

func (h *KafkaHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with the given attributes.

func (*KafkaHandler) WithGroup

func (h *KafkaHandler) WithGroup(name string) slog.Handler

WithGroup returns a new handler with the given group name.

type LogMessage

type LogMessage struct {
	Timestamp      time.Time      `json:"timestamp"`
	Level          string         `json:"level"`
	Message        string         `json:"message"`
	MachineSerial  string         `json:"machineSerial,omitempty"`
	BMCMAC         string         `json:"bmcMac,omitempty"`
	ProvisioningID string         `json:"provisioningId,omitempty"`
	Step           string         `json:"step,omitempty"`
	Attrs          map[string]any `json:"attrs,omitempty"`
}

LogMessage is the structured Kafka message format.

type MachineIdentity

type MachineIdentity struct {
	Serial         string
	BMCMAC         string
	ProvisioningID string
}

MachineIdentity holds machine identification for log enrichment.

type MessageWriter

type MessageWriter interface {
	WriteMessage(topic string, key string, data []byte) error
	Close() error
}

MessageWriter is the interface for sending log messages.

func NewWriterAdapter

func NewWriterAdapter(w io.Writer) MessageWriter

NewWriterAdapter creates a MessageWriter that writes JSON lines to w.

type MultiHandler

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

MultiHandler fans out log records to multiple handlers.

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

NewMultiHandler creates a handler that sends to all given handlers.

func (*MultiHandler) Enabled

func (m *MultiHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns true if any handler is enabled for the level.

func (*MultiHandler) Handle

func (m *MultiHandler) Handle(ctx context.Context, r slog.Record) error

Handle sends the record to all enabled handlers, collecting errors.

func (*MultiHandler) WithAttrs

func (m *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new MultiHandler with attrs applied to all handlers.

func (*MultiHandler) WithGroup

func (m *MultiHandler) WithGroup(name string) slog.Handler

WithGroup returns a new MultiHandler with the group applied to all handlers.

Jump to

Keyboard shortcuts

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