sloghelper

package
v0.0.0-...-2bf1e3b Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Duration

func Duration(key string, value time.Duration) slog.Attr

func Error

func Error(key string, value error) slog.Attr

func Int

func Int(key string, value int) slog.Attr

func Int32

func Int32(key string, value int32) slog.Attr

func Int64

func Int64(key string, value int64) slog.Attr

func Interface

func Interface(key string, value interface{}) slog.Attr

func String

func String(key, value string) slog.Attr

func Uint32

func Uint32(key string, value uint32) slog.Attr

func Uint64

func Uint64(key string, value uint64) slog.Attr

Types

type DiscardHandler

type DiscardHandler struct{}

log/slog currently doesn't have a cheap and fast way to implement a discard logger, though it does appear to be coming soon (see: https://github.com/golang/go/issues/62005). This implements this function in the short term until it can be officially added.

func (DiscardHandler) Enabled

func (DiscardHandler) Handle

func (DiscardHandler) WithAttrs

func (d DiscardHandler) WithAttrs([]slog.Attr) slog.Handler

func (DiscardHandler) WithGroup

func (d DiscardHandler) WithGroup(string) slog.Handler

type Leveler

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

func (*Leveler) Level

func (l *Leveler) Level() slog.Level

func (*Leveler) SetLevel

func (l *Leveler) SetLevel(level slog.Level)

type Rotator

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

This is partial implementation of a slog.Handler that will handle output to a file/console while also supporting concepts like rotation. This functionality is not present in the default slog Handlers.

Note that this does not perform moves on the underlying file. It is assumed that something like logrotate will be handling that.

func NewRotator

func NewRotator(ctx context.Context, file string) (*Rotator, error)

func (*Rotator) Rotate

func (r *Rotator) Rotate(ctx context.Context) error

Opens the file on disk.

func (*Rotator) Write

func (r *Rotator) Write(data []byte) (int, error)

Acts like a io.Writter, allowing raw data to be written to the current log buffer. Note that this does not lock as its assumed that this will be called from within something that is locking propertly.

Jump to

Keyboard shortcuts

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