logsink

package
v0.0.0-...-0a271de Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency manifold that runs a log sink worker, using the resource names defined in the supplied config.

func NewModelLogger

func NewModelLogger(
	ctx context.Context,
	key corelogger.LoggerKey,
	config ModelLoggerConfig,
) (worker.Worker, error)

NewModelLogger returns a new model logger instance.

func NewWorker

func NewWorker(cfg Config) (worker.Worker, error)

NewWorker returns a new worker which provides access to a log sink which allows log entries to be stored for specified models.

Types

type Config

type Config struct {
	Logger                logger.Logger
	Clock                 clock.Clock
	LogSinkConfig         LogSinkConfig
	MachineID             string
	NewModelLogger        NewModelLoggerFunc
	LogWriterForModelFunc logger.LogWriterForModelFunc
	ModelService          ModelService
}

Config defines the attributes used to create a log sink worker.

type LogSink

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

LogSink is a worker which provides access to a log sink which allows log entries to be stored for specified models.

func (*LogSink) Close

func (w *LogSink) Close() error

Close closes all the log writers.

func (*LogSink) GetLogWriter

func (w *LogSink) GetLogWriter(ctx context.Context, modelUUID model.UUID) (logger.LogWriterCloser, error)

GetLogWriter returns a log writer for the specified model UUID. It is an error if the log writer is not running. Call InitializeLogger to start the log writer.

func (*LogSink) GetLoggerContext

func (w *LogSink) GetLoggerContext(ctx context.Context, modelUUID model.UUID) (logger.LoggerContext, error)

GetLoggerContext returns a logger context for the specified model UUID. It is an error if the log writer is not running. Call InitializeLogger to start the log writer.

func (*LogSink) Kill

func (w *LogSink) Kill()

Kill implements Worker.Kill()

func (*LogSink) RemoveLogWriter

func (w *LogSink) RemoveLogWriter(modelUUID model.UUID) error

RemoveLogWriter closes then removes a log writer by model UUID. Returns an error if there was a problem closing the logger.

func (*LogSink) Wait

func (w *LogSink) Wait() error

Wait implements Worker.Wait()

type LogSinkConfig

type LogSinkConfig struct {
	// LoggerBufferSize is the capacity of the log sink logger's buffer.
	LoggerBufferSize int

	// LoggerFlushInterval is the amount of time to allow a log record
	// to sit in the buffer before being flushed to the destination logger.
	LoggerFlushInterval time.Duration
}

LogSinkConfig holds parameters to control the log sink's behaviour.

func DefaultLogSinkConfig

func DefaultLogSinkConfig() LogSinkConfig

DefaultLogSinkConfig returns a LogSinkConfig with default values.

func (LogSinkConfig) Validate

func (cfg LogSinkConfig) Validate() error

Validate validates the logsink endpoint configuration.

type LogSinkWriter

type LogSinkWriter interface {
	logger.LogWriterCloser
	logger.LoggerContext
}

LogSinkWriter is a writer that writes log records to a log sink.

type ManifoldConfig

type ManifoldConfig struct {
	// DebugLogger is used to emit debug messages.
	DebugLogger corelogger.Logger

	// NewWorker creates a log sink worker.
	NewWorker func(cfg Config) (worker.Worker, error)

	// NewModelLogger creates a new model logger.
	NewModelLogger NewModelLoggerFunc

	// ModelServiceGetter returns the model service.
	ModelServiceGetter ModelServiceGetterFunc

	ClockName       string
	LogSinkServices string
	AgentName       string
}

ManifoldConfig defines the names of the manifolds on which a Manifold will depend.

func (ManifoldConfig) Validate

func (config ManifoldConfig) Validate() error

Validate validates the manifold configuration.

type ModelLoggerConfig

type ModelLoggerConfig struct {
	MachineID     string
	NewLogWriter  corelogger.LogWriterForModelFunc
	BufferSize    int
	FlushInterval time.Duration
	Clock         clock.Clock
}

ModelLoggerConfig holds the configuration for a model logger.

type ModelService

type ModelService interface {
	// Model returns the model information.
	Model(ctx context.Context, modelUUID model.UUID) (model.ModelInfo, error)
}

ModelService is an interface that provides model information.

func NewModelService

func NewModelService(servicesGetter services.LogSinkServicesGetter) ModelService

NewModelService returns a new model service.

type ModelServiceGetterFunc

type ModelServiceGetterFunc func(services.LogSinkServicesGetter) ModelService

ModelServiceGetterFunc is a function that returns the model service.

type NewModelLoggerFunc

type NewModelLoggerFunc func(ctx context.Context,
	key corelogger.LoggerKey,
	cfg ModelLoggerConfig) (worker.Worker, error)

NewModelLoggerFunc is a function that creates a new model logger.

Jump to

Keyboard shortcuts

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