logging

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Level:  LevelDefault,
	Format: FormatDefault,
}

DefaultOptions holds defaults for creating a Logger.

Functions

This section is empty.

Types

type EnabledAware

type EnabledAware interface {
	Enabled(context.Context, slog.Level) bool
}

type Format

type Format string

Format represents a text format to use when writing logs.

const (
	FormatLogfmt Format = "logfmt"
	FormatJSON   Format = "json"

	FormatDefault = FormatLogfmt
)

Supported log formats.

func (Format) MarshalText

func (ll Format) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (*Format) UnmarshalText

func (ll *Format) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Level

type Level string

Level represents how verbose logging should be.

const (
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"

	LevelDefault = LevelInfo
)

Supported log levels

func (Level) MarshalText

func (ll Level) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (*Level) UnmarshalText

func (ll *Level) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Logger

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

Logger is the logging subsystem of Alloy. It supports being dynamically updated at runtime.

func New

func New(w io.Writer, o Options) (*Logger, error)

New creates a New logger with the default log level and format.

func NewDeferred

func NewDeferred(w io.Writer) (*Logger, error)

NewDeferred creates a new logger with the default log level and format. The logger is not updated during initialization.

func NewNop added in v1.5.0

func NewNop() *Logger

NewNop returns a logger that does nothing

func (*Logger) Enabled

func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool

Enabled implements EnabledAware interface.

func (*Logger) Handler

func (l *Logger) Handler() slog.Handler

Handler returns a slog.Handler. The returned Handler remains valid if l is updated.

func (*Logger) Log

func (l *Logger) Log(kvps ...interface{}) error

Log implements log.Logger.

func (*Logger) RemoveTemporaryWriter added in v1.5.0

func (l *Logger) RemoveTemporaryWriter()

func (*Logger) SetTemporaryWriter added in v1.5.0

func (l *Logger) SetTemporaryWriter(w io.Writer)

func (*Logger) Update

func (l *Logger) Update(o Options) error

Update re-configures the options used for the logger.

type Options

type Options struct {
	Level  Level  `alloy:"level,attr,optional"`
	Format Format `alloy:"format,attr,optional"`

	WriteTo []loki.LogsReceiver `alloy:"write_to,attr,optional"`
}

Options is a set of options used to construct and configure a Logger.

func (*Options) SetToDefault

func (o *Options) SetToDefault()

SetToDefault implements syntax.Defaulter.

type SlogGoKitHandler added in v1.6.0

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

SlogGoKitHandler is an slog.Handler that wraps a go-kit logger. This is specific to Alloy's logging system, as we expect the go-kit logger to be configured with the correct level.

func NewSlogGoKitHandler added in v1.6.0

func NewSlogGoKitHandler(logger log.Logger) *SlogGoKitHandler

func (SlogGoKitHandler) Enabled added in v1.6.0

func (h SlogGoKitHandler) Enabled(ctx context.Context, level slog.Level) bool

func (SlogGoKitHandler) Handle added in v1.6.0

func (h SlogGoKitHandler) Handle(ctx context.Context, record slog.Record) error

func (SlogGoKitHandler) WithAttrs added in v1.6.0

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

func (SlogGoKitHandler) WithGroup added in v1.6.0

func (h SlogGoKitHandler) WithGroup(name string) slog.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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