log

package
v0.0.0-...-d73ec67 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDebugLogger

func CreateDebugLogger(logdir string, name string)

func CreateDefaultLogger

func CreateDefaultLogger(logdir string, name string)

func NewChannelHandler

func NewChannelHandler() slog.Handler

NewChannelHandler creates a new ChannelHandler struct and returns it.

func NewDispatchHandler

func NewDispatchHandler(handlers ...slog.Handler) slog.Handler

NewDispatchHandler creates a new dispatchHandler.

func NewFileHandler

func NewFileHandler(path string, name string) slog.Handler

NewFileHandler creates a new file handler

func NewFileHandlerWithLevel

func NewFileHandlerWithLevel(path string, name string, l slog.Level) slog.Handler

NewfileHandler creates a new file handler that only logs lines with a level equalt to or higher than the provided level.

func Subscribe

func Subscribe(level slog.Level, chnl chan slog.Record) (key string)

Subscribe subscribes to log events. The key identifies the subscription and can be used to unsubscribe at a later stage.

func Unsubscribe

func Unsubscribe(key string)

Unsubscribe from a log event by giving the subscription key.

Types

type ChannelHandler

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

func (*ChannelHandler) Enabled

func (h *ChannelHandler) Enabled(_ context.Context, l slog.Level) bool

Enabled checks if the channel handler is enabled for a given log level

func (*ChannelHandler) Handle

func (h *ChannelHandler) Handle(ctx context.Context, r slog.Record) error

Handle forwards the log record on the subcribed channels.

func (*ChannelHandler) Subscribe

func (h *ChannelHandler) Subscribe(
	key string,
	level slog.Level,
	chnl chan slog.Record,
)

Subscribe is used to subscribe to a channel. It takes a string key, a slog.Level level, and a channel of slog.Records as parameters.

func (*ChannelHandler) Unsubscribe

func (h *ChannelHandler) Unsubscribe(key string)

Unsubscribe is used to unsubscribe a key from the channel handler

func (*ChannelHandler) WithAttrs

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

WithAttrs takes a slice of Attrs as parameters and returns a Handler.

func (*ChannelHandler) WithGroup

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

WithGroup creates a new handler with the given group name

type DispatchHandler

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

DispatchHandler dispatches the incomming log record to the configured handlers.

func (*DispatchHandler) Enabled

func (h *DispatchHandler) Enabled(ctx context.Context, l slog.Level) bool

Enabled implements slog.Handler. As soon as one of the child handlers is enabled for the log level, true is returned; otherwise false.

func (*DispatchHandler) Handle

func (h *DispatchHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements slog.Handler.

func (*DispatchHandler) WithAttrs

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

WithAttrs implements slog.Handler.

func (*DispatchHandler) WithGroup

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

WithGroup implements slog.Handler.

type FileHandler

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

FileHandler writes log lines to a file on disk. It is a thread-safe impelmentation.

func (*FileHandler) Enabled

func (h *FileHandler) Enabled(_ context.Context, l slog.Level) bool

Enabled implements slog.Handler

func (*FileHandler) GetDelimiter

func (h *FileHandler) GetDelimiter() byte

GetDelimiter returns the delimiter used in the log file. Default delimiter = ';'

func (*FileHandler) Handle

func (h *FileHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements slog.Handler

func (*FileHandler) SetDelimiter

func (h *FileHandler) SetDelimiter(d byte)

SetDelimiter allows you to set the delimiter

func (*FileHandler) WithAttrs

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

WithAttrs implements slog.Handler.

func (*FileHandler) WithGroup

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

WithGroup implements slog.Handler

Jump to

Keyboard shortcuts

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