log

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext returns the logger from context, or new logger if not present in context

func NewContext

func NewContext(ctx context.Context, v slog.Logger) context.Context

NewContext returns a new context with logger.

func SetupContext

func SetupContext(ctx context.Context, defaultWriter io.Writer) context.Context

SetupContext creates supplies a context.Context with new Logger instance It handles setting up logging level and log output

func WithCommand

func WithCommand(ctx context.Context, command string) *slog.Logger

WithCommand returns a Logger supplied with given 'command' field

func WithCommandContext

func WithCommandContext(ctx context.Context, command string) context.Context

WithCommandContext returns a context withe a logger and supplied with given 'command' field

Types

type Handler

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

Handler is a custom slog handler

func NewHandler

func NewHandler(w io.Writer, coloredOutput bool, opts *slog.HandlerOptions) *Handler

NewHandler returns configured SlogHandler

func (*Handler) Enabled

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

Enabled is a wrapper over slog.Handler.Enabled method

func (*Handler) Handle

func (h *Handler) Handle(_ context.Context, r slog.Record) error

Handle handles the Record It will only be called when Enabled returns true

func (*Handler) WithAttrs

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

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.

func (*Handler) WithGroup

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

WithGroup returns a new Handler with the given group appended to the receiver's existing groups.

Jump to

Keyboard shortcuts

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