logging

package
v0.302.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: Apache-2.0 Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deduper

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

Deduper implements *slog.Handler, dedupes log lines based on a time duration.

func Dedupe

func Dedupe(next *slog.Logger, repeat time.Duration) *Deduper

Dedupe log lines to next, only repeating every repeat duration.

func (*Deduper) Enabled added in v0.300.0

func (d *Deduper) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns true if the Deduper's internal slog.Logger is enabled at the provided context and log level, and returns false otherwise. It implements slog.Handler.

func (*Deduper) Handle added in v0.300.0

func (d *Deduper) Handle(ctx context.Context, r slog.Record) error

Handle uses the provided context and slog.Record to deduplicate messages every 1m. Log records received within the interval are not acted on, and thus dropped. Log records that pass deduplication and need action invoke the Handle() method on the Deduper's internal slog.Logger's handler, effectively chaining log calls to the internal slog.Logger.

func (*Deduper) Stop

func (d *Deduper) Stop()

Stop the Deduper.

func (*Deduper) WithAttrs added in v0.300.0

func (d *Deduper) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs adds the provided attributes to the Deduper's internal slog.Logger. It implements slog.Handler.

func (*Deduper) WithGroup added in v0.300.0

func (d *Deduper) WithGroup(name string) slog.Handler

WithGroup adds the provided group name to the Deduper's internal slog.Logger. It implements slog.Handler.

type JSONFileLogger

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

JSONFileLogger represents a logger that writes JSON to a file. It implements the slog.Handler interface, as well as the io.Closer interface.

func NewJSONFileLogger

func NewJSONFileLogger(s string) (*JSONFileLogger, error)

NewJSONFileLogger returns a new JSONFileLogger.

func (*JSONFileLogger) Close

func (l *JSONFileLogger) Close() error

Close closes the underlying file. It implements the io.Closer interface.

func (*JSONFileLogger) Enabled

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

Enabled returns true if and only if the internal slog.Handler is enabled. It implements the slog.Handler interface.

func (*JSONFileLogger) Handle

func (l *JSONFileLogger) Handle(ctx context.Context, r slog.Record) error

Handle takes record created by an slog.Logger and forwards it to the internal slog.Handler for dispatching the log call to the backing file. It implements the slog.Handler interface.

func (*JSONFileLogger) WithAttrs

func (l *JSONFileLogger) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new *JSONFileLogger with a new internal handler that has the provided attrs attached as attributes on all further log calls. It implements the slog.Handler interface.

func (*JSONFileLogger) WithGroup

func (l *JSONFileLogger) WithGroup(name string) slog.Handler

WithGroup returns a new *JSONFileLogger with a new internal handler that has the provided group name attached, to group all other attributes added to the logger. It implements the slog.Handler interface.

Jump to

Keyboard shortcuts

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